diff options
author | sdefresne <sdefresne@chromium.org> | 2016-02-03 08:53:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-03 16:55:17 +0000 |
commit | 761098fba97c6ec094e241b61ecf879134ab7922 (patch) | |
tree | c766580a8b8b55f34ea768f7c9888a12a3e62a4a | |
parent | a77aeb0b3a2d5d08793f88824be3112f8e0cfc64 (diff) | |
download | chromium_src-761098fba97c6ec094e241b61ecf879134ab7922.zip chromium_src-761098fba97c6ec094e241b61ecf879134ab7922.tar.gz chromium_src-761098fba97c6ec094e241b61ecf879134ab7922.tar.bz2 |
Implement some methods of ChromeBrowserState.
Implement the methods shared between all ChromeBrowserState
sub-classes.
BUG=429756
Review URL: https://codereview.chromium.org/1667743002
Cr-Commit-Position: refs/heads/master@{#373256}
-rw-r--r-- | ios/chrome/browser/browser_state/DEPS | 7 | ||||
-rw-r--r-- | ios/chrome/browser/browser_state/chrome_browser_state.cc | 46 | ||||
-rw-r--r-- | ios/chrome/browser/browser_state/chrome_browser_state.h | 22 |
3 files changed, 70 insertions, 5 deletions
diff --git a/ios/chrome/browser/browser_state/DEPS b/ios/chrome/browser/browser_state/DEPS new file mode 100644 index 0000000..696db98 --- /dev/null +++ b/ios/chrome/browser/browser_state/DEPS @@ -0,0 +1,7 @@ +specific_include_rules = { + "chrome_browser_state.cc": [ + # TODO(crbug.com/583685): remove once the //ios/web public API allow + # access to that class. + "+ios/web/webui/url_data_manager_ios_backend.h" + ] +} diff --git a/ios/chrome/browser/browser_state/chrome_browser_state.cc b/ios/chrome/browser/browser_state/chrome_browser_state.cc index 2926e02..adb2333 100644 --- a/ios/chrome/browser/browser_state/chrome_browser_state.cc +++ b/ios/chrome/browser/browser_state/chrome_browser_state.cc @@ -4,12 +4,28 @@ #include "ios/chrome/browser/browser_state/chrome_browser_state.h" +#include <utility> + #include "base/files/file_path.h" +#include "base/logging.h" +#include "base/sequenced_task_runner.h" +#include "components/prefs/json_pref_store.h" +#include "components/syncable_prefs/pref_service_syncable.h" +#include "ios/chrome/browser/chrome_url_constants.h" +#include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h" +#include "ios/chrome/browser/net/net_types.h" #include "ios/public/provider/web/web_ui_ios.h" #include "ios/web/public/web_state/web_state.h" +#include "ios/web/public/web_thread.h" +#include "ios/web/webui/url_data_manager_ios_backend.h" +#include "net/url_request/url_request_interceptor.h" namespace ios { +ChromeBrowserState::ChromeBrowserState() {} + +ChromeBrowserState::~ChromeBrowserState() {} + // static ChromeBrowserState* ChromeBrowserState::FromBrowserState( web::BrowserState* browser_state) { @@ -33,4 +49,34 @@ std::string ChromeBrowserState::GetDebugName() { return name; } +scoped_refptr<base::SequencedTaskRunner> ChromeBrowserState::GetIOTaskRunner() { + base::FilePath browser_state_path = + GetOriginalChromeBrowserState()->GetStatePath(); + return JsonPrefStore::GetTaskRunnerForFile(browser_state_path, + web::WebThread::GetBlockingPool()); +} + +syncable_prefs::PrefServiceSyncable* ChromeBrowserState::GetSyncablePrefs() { + return static_cast<syncable_prefs::PrefServiceSyncable*>(GetPrefs()); +} + +TestChromeBrowserState* ChromeBrowserState::AsTestChromeBrowserState() { + return nullptr; +} + +net::URLRequestContextGetter* ChromeBrowserState::GetRequestContext() { + DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); + if (!request_context_getter_) { + ProtocolHandlerMap protocol_handlers; + protocol_handlers[kChromeUIScheme] = + linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( + web::URLDataManagerIOSBackend::CreateProtocolHandler(this) + .release()); + URLRequestInterceptorScopedVector request_interceptors; + request_context_getter_ = make_scoped_refptr(CreateRequestContext( + &protocol_handlers, std::move(request_interceptors))); + } + return request_context_getter_.get(); +} + } // namespace ios diff --git a/ios/chrome/browser/browser_state/chrome_browser_state.h b/ios/chrome/browser/browser_state/chrome_browser_state.h index b04c33e..31548b9 100644 --- a/ios/chrome/browser/browser_state/chrome_browser_state.h +++ b/ios/chrome/browser/browser_state/chrome_browser_state.h @@ -21,6 +21,7 @@ class ChromeBrowserStateIOData; class PrefProxyConfigTracker; class PrefService; class TestChromeBrowserState; +class TestChromeBrowserStateManager; namespace base { class SequencedTaskRunner; @@ -50,7 +51,7 @@ enum class ChromeBrowserStateType { // This class is a Chrome-specific extension of the BrowserState interface. class ChromeBrowserState : public web::BrowserState { public: - ~ChromeBrowserState() override {} + ~ChromeBrowserState() override; // Returns the ChromeBrowserState corresponding to the given BrowserState. static ChromeBrowserState* FromBrowserState(BrowserState* browser_state); @@ -60,7 +61,7 @@ class ChromeBrowserState : public web::BrowserState { // Returns sequenced task runner where browser state dependent I/O // operations should be performed. - virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() = 0; + virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner(); // Returns the original "recording" ChromeBrowserState. This method returns // |this| if the ChromeBrowserState is not incognito. @@ -96,7 +97,7 @@ class ChromeBrowserState : public web::BrowserState { // Retrieves a pointer to the PrefService that manages the preferences as // a syncable_prefs::PrefServiceSyncable. - virtual syncable_prefs::PrefServiceSyncable* GetSyncablePrefs() = 0; + virtual syncable_prefs::PrefServiceSyncable* GetSyncablePrefs(); // Deletes all network related data since |time|. It deletes transport // security state since |time| and it also deletes HttpServerProperties data. @@ -132,12 +133,23 @@ class ChromeBrowserState : public web::BrowserState { // Returns the current ChromeBrowserState casted as a TestChromeBrowserState // or null if it is not a TestChromeBrowserState. - virtual TestChromeBrowserState* AsTestChromeBrowserState() = 0; + // TODO(crbug.com/583682): This method should not be used. It is there for + // supporting a legacy test, and will be removed as soon as the deprecated + // test is removed. + virtual TestChromeBrowserState* AsTestChromeBrowserState(); + + // web::BrowserState + net::URLRequestContextGetter* GetRequestContext() override; protected: - ChromeBrowserState() {} + ChromeBrowserState(); private: + friend class ::TestChromeBrowserState; + friend class ::TestChromeBrowserStateManager; + + scoped_refptr<net::URLRequestContextGetter> request_context_getter_; + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserState); }; |