OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #include "chrome/browser/net/spdy_config_service_manager.h" |
| 5 |
| 6 #include <string> |
| 7 |
| 8 #include "content/browser/browser_thread.h" |
| 9 |
| 10 //////////////////////////////////////////////////////////////////////////////// |
| 11 // SpdyConfigServicePref |
| 12 |
| 13 SpdyConfigServicePref::SpdyConfigServicePref() { |
| 14 } |
| 15 |
| 16 SpdyConfigServicePref::~SpdyConfigServicePref() { |
| 17 } |
| 18 |
| 19 void SpdyConfigServicePref::GetSpdyConfig(net::SpdyConfig* config) { |
| 20 *config = cached_config_; |
| 21 } |
| 22 |
| 23 void SpdyConfigServicePref::AddSpdyServer(const std::string& spdy_server) { |
| 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 25 if (cached_config_.spdy_servers.find(spdy_server) != std::string::npos) |
| 26 return; |
| 27 // Copy the data. |
| 28 cached_config_.spdy_servers.append(spdy_server); |
| 29 BrowserThread::PostTask( |
| 30 BrowserThread::UI, |
| 31 FROM_HERE, |
| 32 NewRunnableMethod(spdy_config_service_manager_.get(), |
| 33 &SpdyConfigServiceManager::SetSpdyConfigInPrefs)); |
| 34 } |
| 35 |
| 36 //////////////////////////////////////////////////////////////////////////////// |
| 37 // SpdyConfigServiceManager |
| 38 |
| 39 SpdyConfigServiceManager::SpdyConfigServiceManager() |
| 40 : spdy_config_service_(new SpdyConfigServicePref()) { |
| 41 spdy_config_service_->spdy_config_service_manager_ = this; |
| 42 spdy_config_service_->cached_config_.spdy_servers = std::string(); |
| 43 } |
| 44 |
| 45 SpdyConfigServiceManager::~SpdyConfigServiceManager() { |
| 46 } |
| 47 |
| 48 net::SpdyConfigService* SpdyConfigServiceManager::Get() { |
| 49 return spdy_config_service_; |
| 50 } |
| 51 |
| 52 // static |
| 53 void SpdyConfigServiceManager::RegisterPrefs(PrefService* prefs) { |
| 54 prefs->RegisterStringPref( |
| 55 prefs::kSpdyServers, std::string(), PrefService::UNSYNCABLE_PREF); |
| 56 } |
| 57 |
| 58 void SpdyConfigServiceManager::Initialize(PrefService* prefs) { |
| 59 DCHECK(prefs); |
| 60 |
| 61 spdy_servers_.Init(prefs::kSpdyServers, prefs, this); |
| 62 pref_change_registrar_.Init(prefs); |
| 63 |
| 64 // Initialize from UI thread. This is okay as there shouldn't be anything on |
| 65 // the IO thread trying to access it yet. |
| 66 spdy_config_service_->cached_config_.spdy_servers = |
| 67 spdy_servers_.GetValue(); |
| 68 } |
| 69 |
| 70 void SpdyConfigServiceManager::Cleanup() { |
| 71 spdy_config_service_->spdy_config_service_manager_ = NULL; |
| 72 spdy_servers_.Destroy(); |
| 73 } |
| 74 |
| 75 void SpdyConfigServiceManager::SetSpdyConfigInPrefs() { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 77 spdy_servers_.SetValue(spdy_config_service_->cached_config_.spdy_servers); |
| 78 } |
| 79 |
| 80 void SpdyConfigServiceManager::Observe(int type, |
| 81 const NotificationSource& source, |
| 82 const NotificationDetails& details) { |
| 83 } |
OLD | NEW |