| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 5 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/sequenced_task_runner.h" |
| 12 #include "components/prefs/json_pref_store.h" |
| 13 #include "components/syncable_prefs/pref_service_syncable.h" |
| 14 #include "ios/chrome/browser/chrome_url_constants.h" |
| 15 #include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h" |
| 16 #include "ios/chrome/browser/net/net_types.h" |
| 8 #include "ios/public/provider/web/web_ui_ios.h" | 17 #include "ios/public/provider/web/web_ui_ios.h" |
| 9 #include "ios/web/public/web_state/web_state.h" | 18 #include "ios/web/public/web_state/web_state.h" |
| 19 #include "ios/web/public/web_thread.h" |
| 20 #include "ios/web/webui/url_data_manager_ios_backend.h" |
| 21 #include "net/url_request/url_request_interceptor.h" |
| 10 | 22 |
| 11 namespace ios { | 23 namespace ios { |
| 12 | 24 |
| 25 ChromeBrowserState::ChromeBrowserState() {} |
| 26 |
| 27 ChromeBrowserState::~ChromeBrowserState() {} |
| 28 |
| 13 // static | 29 // static |
| 14 ChromeBrowserState* ChromeBrowserState::FromBrowserState( | 30 ChromeBrowserState* ChromeBrowserState::FromBrowserState( |
| 15 web::BrowserState* browser_state) { | 31 web::BrowserState* browser_state) { |
| 16 // This is safe; this is the only implementation of BrowserState. | 32 // This is safe; this is the only implementation of BrowserState. |
| 17 return static_cast<ChromeBrowserState*>(browser_state); | 33 return static_cast<ChromeBrowserState*>(browser_state); |
| 18 } | 34 } |
| 19 | 35 |
| 20 // static | 36 // static |
| 21 ChromeBrowserState* ChromeBrowserState::FromWebUIIOS(web::WebUIIOS* web_ui) { | 37 ChromeBrowserState* ChromeBrowserState::FromWebUIIOS(web::WebUIIOS* web_ui) { |
| 22 return FromBrowserState(web_ui->GetWebState()->GetBrowserState()); | 38 return FromBrowserState(web_ui->GetWebState()->GetBrowserState()); |
| 23 } | 39 } |
| 24 | 40 |
| 25 std::string ChromeBrowserState::GetDebugName() { | 41 std::string ChromeBrowserState::GetDebugName() { |
| 26 // The debug name is based on the state path of the original browser state | 42 // The debug name is based on the state path of the original browser state |
| 27 // to keep in sync with the meaning on other platforms. | 43 // to keep in sync with the meaning on other platforms. |
| 28 std::string name = | 44 std::string name = |
| 29 GetOriginalChromeBrowserState()->GetStatePath().BaseName().MaybeAsASCII(); | 45 GetOriginalChromeBrowserState()->GetStatePath().BaseName().MaybeAsASCII(); |
| 30 if (name.empty()) { | 46 if (name.empty()) { |
| 31 name = "UnknownBrowserState"; | 47 name = "UnknownBrowserState"; |
| 32 } | 48 } |
| 33 return name; | 49 return name; |
| 34 } | 50 } |
| 35 | 51 |
| 52 scoped_refptr<base::SequencedTaskRunner> ChromeBrowserState::GetIOTaskRunner() { |
| 53 base::FilePath browser_state_path = |
| 54 GetOriginalChromeBrowserState()->GetStatePath(); |
| 55 return JsonPrefStore::GetTaskRunnerForFile(browser_state_path, |
| 56 web::WebThread::GetBlockingPool()); |
| 57 } |
| 58 |
| 59 syncable_prefs::PrefServiceSyncable* ChromeBrowserState::GetSyncablePrefs() { |
| 60 return static_cast<syncable_prefs::PrefServiceSyncable*>(GetPrefs()); |
| 61 } |
| 62 |
| 63 TestChromeBrowserState* ChromeBrowserState::AsTestChromeBrowserState() { |
| 64 return nullptr; |
| 65 } |
| 66 |
| 67 net::URLRequestContextGetter* ChromeBrowserState::GetRequestContext() { |
| 68 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
| 69 if (!request_context_getter_) { |
| 70 ProtocolHandlerMap protocol_handlers; |
| 71 protocol_handlers[kChromeUIScheme] = |
| 72 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 73 web::URLDataManagerIOSBackend::CreateProtocolHandler(this) |
| 74 .release()); |
| 75 URLRequestInterceptorScopedVector request_interceptors; |
| 76 request_context_getter_ = make_scoped_refptr(CreateRequestContext( |
| 77 &protocol_handlers, std::move(request_interceptors))); |
| 78 } |
| 79 return request_context_getter_.get(); |
| 80 } |
| 81 |
| 36 } // namespace ios | 82 } // namespace ios |
| OLD | NEW |