1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IMPL_H_ 6 #define IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IMPL_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 12 #include "ios/chrome/browser/browser_state/chrome_browser_state_impl_io_data.h" 13 14 namespace policy { 15 class SchemaRegistry; 16 } 17 18 namespace sync_preferences { 19 class PrefServiceSyncable; 20 } 21 22 namespace user_prefs { 23 class PrefRegistrySyncable; 24 } 25 26 class PrefProxyConfigTracker; 27 28 // This class is the implementation of ChromeBrowserState used for 29 // non-incognito browsing. 30 class ChromeBrowserStateImpl : public ChromeBrowserState { 31 public: 32 ~ChromeBrowserStateImpl() override; 33 34 // ChromeBrowserState: 35 ChromeBrowserState* GetOriginalChromeBrowserState() override; 36 bool HasOffTheRecordChromeBrowserState() const override; 37 ChromeBrowserState* GetOffTheRecordChromeBrowserState() override; 38 void DestroyOffTheRecordChromeBrowserState() override; 39 PrefProxyConfigTracker* GetProxyConfigTracker() override; 40 BrowserStatePolicyConnector* GetPolicyConnector() override; 41 PrefService* GetPrefs() override; 42 PrefService* GetOffTheRecordPrefs() override; 43 ChromeBrowserStateIOData* GetIOData() override; 44 void ClearNetworkingHistorySince(base::Time time, 45 base::OnceClosure completion) override; 46 net::URLRequestContextGetter* CreateRequestContext( 47 ProtocolHandlerMap* protocol_handlers) override; 48 49 // BrowserState: 50 bool IsOffTheRecord() const override; 51 base::FilePath GetStatePath() const override; 52 53 private: 54 friend class ChromeBrowserStateManagerImpl; 55 56 ChromeBrowserStateImpl( 57 scoped_refptr<base::SequencedTaskRunner> io_task_runner, 58 const base::FilePath& path); 59 60 // Sets the OffTheRecordChromeBrowserState. 61 void SetOffTheRecordChromeBrowserState( 62 std::unique_ptr<ChromeBrowserState> otr_state); 63 64 base::FilePath state_path_; 65 66 // The incognito ChromeBrowserState instance that is associated with this 67 // ChromeBrowserState instance. NULL if |GetOffTheRecordChromeBrowserState()| 68 // has never been called or has not been called since 69 // |DestroyOffTheRecordChromeBrowserState()|. 70 std::unique_ptr<ChromeBrowserState> otr_state_; 71 base::FilePath otr_state_path_; 72 73 // !!! BIG HONKING WARNING !!! 74 // The order of the members below is important. Do not change it unless 75 // you know what you're doing. Also, if adding a new member here make sure 76 // that the declaration occurs AFTER things it depends on as destruction 77 // happens in reverse order of declaration. 78 79 // |policy_connector_| and its associated |policy_schema_registry_| must 80 // outlive |prefs_|. 81 std::unique_ptr<policy::SchemaRegistry> policy_schema_registry_; 82 std::unique_ptr<BrowserStatePolicyConnector> policy_connector_; 83 84 // Keep |prefs_| above the rest for destruction order because |io_data_| and 85 // others store pointers to |prefs_| and shall be destructed first. 86 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; 87 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_; 88 std::unique_ptr<ChromeBrowserStateImplIOData::Handle> io_data_; 89 90 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 91 92 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!! 93 // 94 // Instead, make your Service/Manager/whatever object you're hanging off the 95 // BrowserState use our BrowserStateKeyedServiceFactory system instead. 96 // You can find the design document here: 97 // 98 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture 99 // 100 // and you can read the raw headers here: 101 // 102 // components/keyed_service/ios/browser_state_dependency_manager.* 103 // components/keyed_service/core/keyed_service.h 104 // components/keyed_service/ios/browser_state_keyed_service_factory.* 105 106 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserStateImpl); 107 }; 108 109 #endif // IOS_CHROME_BROWSER_BROWSER_STATE_CHROME_BROWSER_STATE_IMPL_H_ 110