diff options
-rw-r--r-- | chrome/browser/browser_thread.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros_settings_provider_proxy.cc | 24 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros_settings_provider_proxy.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_selection_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/owner_manager.cc | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings.cc | 33 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings.h | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_temp_storage.cc | 77 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_temp_storage.h | 44 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_temp_storage_unittest.cc | 77 | ||||
-rw-r--r-- | chrome/browser/prefs/browser_prefs.cc | 2 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 12 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 4 |
15 files changed, 278 insertions, 18 deletions
diff --git a/chrome/browser/browser_thread.cc b/chrome/browser/browser_thread.cc index 35c1308..003b1ad 100644 --- a/chrome/browser/browser_thread.cc +++ b/chrome/browser/browser_thread.cc @@ -95,7 +95,7 @@ BrowserThread::~BrowserThread() { AutoLock lock(lock_); browser_threads_[identifier_] = NULL; #ifndef NDEBUG - // Double check that the threads are ordererd correctly in the enumeration. + // Double check that the threads are ordered correctly in the enumeration. for (int i = identifier_ + 1; i < ID_COUNT; ++i) { DCHECK(!browser_threads_[i]) << "Threads must be listed in the reverse order that they die"; diff --git a/chrome/browser/chromeos/cros_settings_provider_proxy.cc b/chrome/browser/chromeos/cros_settings_provider_proxy.cc index 7017abb..5fe5916 100644 --- a/chrome/browser/chromeos/cros_settings_provider_proxy.cc +++ b/chrome/browser/chromeos/cros_settings_provider_proxy.cc @@ -7,6 +7,7 @@ #include "base/string_util.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/profile.h" +#include "chrome/browser/profile_manager.h" namespace chromeos { @@ -16,12 +17,10 @@ CrosSettingsProviderProxy::CrosSettingsProviderProxy() { } void CrosSettingsProviderProxy::Set(const std::string& path, Value* in_value) { - Browser* browser = BrowserList::GetLastActive(); - if (!browser || !in_value) { + if (!in_value) { return; } - chromeos::ProxyConfigServiceImpl* config_service = - browser->profile()->GetChromeOSProxyConfigServiceImpl(); + chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); chromeos::ProxyConfigServiceImpl::ProxyConfig config; config_service->UIGetProxyConfig(&config); @@ -187,15 +186,10 @@ void CrosSettingsProviderProxy::Set(const std::string& path, bool CrosSettingsProviderProxy::Get(const std::string& path, Value** out_value) const { - Browser* browser = BrowserList::GetLastActive(); bool found = false; bool managed = false; Value* data; - if (!browser) { - return false; - } - chromeos::ProxyConfigServiceImpl* config_service = - browser->profile()->GetChromeOSProxyConfigServiceImpl(); + chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); chromeos::ProxyConfigServiceImpl::ProxyConfig config; config_service->UIGetProxyConfig(&config); @@ -270,6 +264,16 @@ bool CrosSettingsProviderProxy::HandlesSetting(const std::string& path) { //----------------- CrosSettingsProviderProxy: private methods ----------------- +chromeos::ProxyConfigServiceImpl* + CrosSettingsProviderProxy::GetConfigService() const { + Browser* browser = BrowserList::GetLastActive(); + // browser is NULL at OOBE/login stage. + Profile* profile = browser ? + browser->profile() : + ProfileManager::GetDefaultProfile(); + return profile->GetChromeOSProxyConfigServiceImpl(); +} + void CrosSettingsProviderProxy::AppendPortIfValid( const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, std::string* server_uri) { diff --git a/chrome/browser/chromeos/cros_settings_provider_proxy.h b/chrome/browser/chromeos/cros_settings_provider_proxy.h index ce6712f..26675ec 100644 --- a/chrome/browser/chromeos/cros_settings_provider_proxy.h +++ b/chrome/browser/chromeos/cros_settings_provider_proxy.h @@ -21,6 +21,8 @@ class CrosSettingsProviderProxy : public CrosSettingsProvider { virtual bool HandlesSetting(const std::string& path); private: + chromeos::ProxyConfigServiceImpl* GetConfigService() const; + void AppendPortIfValid( const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, std::string* server_uri); diff --git a/chrome/browser/chromeos/login/network_selection_view.cc b/chrome/browser/chromeos/login/network_selection_view.cc index 62ca881..2543aec 100644 --- a/chrome/browser/chromeos/login/network_selection_view.cc +++ b/chrome/browser/chromeos/login/network_selection_view.cc @@ -79,7 +79,7 @@ const int kMenuWidthOffset = 6; const SkColor kWelcomeColor = 0xFFCDD3D6; // Hints for size of proxy settings dialog. -static const int kProxySettingsDialogReasonableWidth = 700; +static const int kProxySettingsDialogReasonableWidth = 750; static const int kProxySettingsDialogReasonableHeight = 460; static const int kProxySettingsDialogReasonableWidthRatio = 0.4; static const int kProxySettingsDialogReasonableHeightRatio = 0.4; diff --git a/chrome/browser/chromeos/login/owner_manager.cc b/chrome/browser/chromeos/login/owner_manager.cc index b54aa2e..b2715f3 100644 --- a/chrome/browser/chromeos/login/owner_manager.cc +++ b/chrome/browser/chromeos/login/owner_manager.cc @@ -9,7 +9,9 @@ #include "base/file_path.h" #include "base/file_util.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_thread.h" +#include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" @@ -95,7 +97,13 @@ void OwnerManager::OnComplete(bool value) { &OwnerManager::SendNotification, result, NotificationService::NoDetails())); - + // We've stored some settings in transient storage + // before owner has been assigned. + // Now owner is assigned and key is generated and we should persist + // those settings into signed storage. + if (g_browser_process && g_browser_process->local_state()) { + SignedSettingsTempStorage::Finalize(g_browser_process->local_state()); + } } bool OwnerManager::EnsurePublicKey() { diff --git a/chrome/browser/chromeos/login/signed_settings.cc b/chrome/browser/chromeos/login/signed_settings.cc index 524acab..cef4fa1 100644 --- a/chrome/browser/chromeos/login/signed_settings.cc +++ b/chrome/browser/chromeos/login/signed_settings.cc @@ -9,10 +9,12 @@ #include "base/ref_counted.h" #include "base/stringprintf.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/login/ownership_service.h" +#include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" namespace chromeos { @@ -99,6 +101,7 @@ class RetrievePropertyOp : public SignedSettings { SignedSettings* SignedSettings::CreateCheckWhitelistOp( const std::string& email, SignedSettings::Delegate<bool>* d) { + DCHECK(d != NULL); return new CheckWhitelistOp(email, d); } @@ -107,6 +110,7 @@ SignedSettings* SignedSettings::CreateWhitelistOp( const std::string& email, bool add_to_whitelist, SignedSettings::Delegate<bool>* d) { + DCHECK(d != NULL); return new WhitelistOp(email, add_to_whitelist, d); } @@ -115,6 +119,7 @@ SignedSettings* SignedSettings::CreateStorePropertyOp( const std::string& name, const std::string& value, SignedSettings::Delegate<bool>* d) { + DCHECK(d != NULL); return new StorePropertyOp(name, value, d); } @@ -122,6 +127,7 @@ SignedSettings* SignedSettings::CreateStorePropertyOp( SignedSettings* SignedSettings::CreateRetrievePropertyOp( const std::string& name, SignedSettings::Delegate<std::string>* d) { + DCHECK(d != NULL); return new RetrievePropertyOp(name, d); } @@ -224,6 +230,15 @@ StorePropertyOp::StorePropertyOp(const std::string& name, StorePropertyOp::~StorePropertyOp() {} bool StorePropertyOp::Execute() { + if (!service_->IsAlreadyOwned()) { + if (g_browser_process && + g_browser_process->local_state() && + SignedSettingsTempStorage::Store(name_, value_, + g_browser_process->local_state())) { + d_->OnSettingsOpSucceeded(true); + return true; + } + } // Posts a task to the FILE thread to sign |name_|=|value_|. std::string to_sign = base::StringPrintf("%s=%s", name_.c_str(), @@ -273,6 +288,24 @@ RetrievePropertyOp::~RetrievePropertyOp() {} bool RetrievePropertyOp::Execute() { CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); + // TODO(dilmah): Fix the race: + // At the moment when device becomes owned there is lapse of time after + // device has been owned and before temp_storage settings are finally + // persisted into signed settings. + // In this lapse of time Retrieve loses access to those settings. + if (!service_->IsAlreadyOwned()) { + if (g_browser_process && + g_browser_process->local_state() && + SignedSettingsTempStorage::Retrieve( + name_, &value_, g_browser_process->local_state())) { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + NewRunnableMethod(this, + &RetrievePropertyOp::OnKeyOpComplete, + OwnerManager::SUCCESS, std::vector<uint8>())); + return true; + } + } std::vector<uint8> sig; if (!CrosLibrary::Get()->GetLoginLibrary()->RetrieveProperty(name_, &value_, diff --git a/chrome/browser/chromeos/login/signed_settings.h b/chrome/browser/chromeos/login/signed_settings.h index 8882d7e..d1bdc33 100644 --- a/chrome/browser/chromeos/login/signed_settings.h +++ b/chrome/browser/chromeos/login/signed_settings.h @@ -39,8 +39,8 @@ class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, class Delegate { public: // These methods will be called on the UI thread. - virtual void OnSettingsOpSucceeded(T value) = 0; - virtual void OnSettingsOpFailed() = 0; + virtual void OnSettingsOpSucceeded(T value) {} + virtual void OnSettingsOpFailed() {} }; SignedSettings(); diff --git a/chrome/browser/chromeos/login/signed_settings_temp_storage.cc b/chrome/browser/chromeos/login/signed_settings_temp_storage.cc new file mode 100644 index 0000000..d88b075 --- /dev/null +++ b/chrome/browser/chromeos/login/signed_settings_temp_storage.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" + +#include "base/values.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/chromeos/login/ownership_service.h" +#include "chrome/browser/chromeos/login/signed_settings.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/common/pref_names.h" + +namespace chromeos { + +// static +void SignedSettingsTempStorage::RegisterPrefs(PrefService* local_state) { + local_state->RegisterDictionaryPref(prefs::kSignedSettingsTempStorage); +} + +// static +bool SignedSettingsTempStorage::Store(const std::string& name, + const std::string& value, + PrefService* local_state) { + if (local_state) { + DictionaryValue* temp_storage = + local_state->GetMutableDictionary(prefs::kSignedSettingsTempStorage); + if (temp_storage) { + temp_storage->SetWithoutPathExpansion(name, + Value::CreateStringValue(value)); + return true; + } + } + return false; +} + +// static +bool SignedSettingsTempStorage::Retrieve(const std::string& name, + std::string* value, + PrefService* local_state) { + if (local_state) { + const DictionaryValue* temp_storage = + local_state->GetDictionary(prefs::kSignedSettingsTempStorage); + if (temp_storage && temp_storage->HasKey(name)) { + temp_storage->GetStringWithoutPathExpansion(name, value); + return true; + } + } + return false; +} + +// static +void SignedSettingsTempStorage::Finalize(PrefService* local_state) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (local_state) { + const DictionaryValue* temp_storage = + local_state->GetDictionary(prefs::kSignedSettingsTempStorage); + if (temp_storage) { + // We've stored some settings in transient storage + // before owner has been assigned. + // Now owner is assigned and key is generated and we should persist + // those settings into signed storage. + for (DictionaryValue::key_iterator it = temp_storage->begin_keys(); + it != temp_storage->end_keys(); + ++it) { + std::string value; + temp_storage->GetStringWithoutPathExpansion(*it, &value); + SignedSettings::CreateStorePropertyOp( + *it, value, + Singleton< SignedSettings::Delegate<bool> >::get())->Execute(); + } + local_state->ClearPref(prefs::kSignedSettingsTempStorage); + } + } +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/login/signed_settings_temp_storage.h b/chrome/browser/chromeos/login/signed_settings_temp_storage.h new file mode 100644 index 0000000..f7ae0f5 --- /dev/null +++ b/chrome/browser/chromeos/login/signed_settings_temp_storage.h @@ -0,0 +1,44 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_TEMP_STORAGE_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_TEMP_STORAGE_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" + +class PrefService; + +namespace chromeos { + +// There is need (proxy settings at OOBE stage) to store settings +// (that are normally go into SignedSettings storage) +// before owner has been assigned (hence no key is available). +// This class serves as a transient storage in that case. +class SignedSettingsTempStorage { + public: + // Registers required pref section. + static void RegisterPrefs(PrefService* local_state); + + static bool Store(const std::string& name, + const std::string& value, + PrefService* local_state); + static bool Retrieve(const std::string& name, + std::string* value, + PrefService* local_state); + + // Call this after owner has been assigned to persist settings + // into SignedSettings storage. + static void Finalize(PrefService* local_state); + + private: + SignedSettingsTempStorage() {} + DISALLOW_COPY_AND_ASSIGN(SignedSettingsTempStorage); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_TEMP_STORAGE_H_ diff --git a/chrome/browser/chromeos/login/signed_settings_temp_storage_unittest.cc b/chrome/browser/chromeos/login/signed_settings_temp_storage_unittest.cc new file mode 100644 index 0000000..1c18582 --- /dev/null +++ b/chrome/browser/chromeos/login/signed_settings_temp_storage_unittest.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" + +#include <algorithm> +#include <iterator> +#include <map> +#include <vector> + +#include "base/file_util.h" +#include "base/scoped_temp_dir.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/common/logging_chrome.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace chromeos { + +class SignedSettingsTempStorageTest : public ::testing::Test { + protected: + virtual void SetUp() { + ref_map_["some_stuff"] = "a=35;code=64"; + ref_map_["another_stuff"] = ""; + ref_map_["name"] = "value"; + ref_map_["2bc6aa16-e0ea-11df-b13d-18a90520e2e5"] = "512"; + + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + FilePath temp_file; + ASSERT_TRUE( + file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); + local_state_ = PrefService::CreatePrefService(temp_file, NULL); + ASSERT_TRUE(NULL != local_state_); + SignedSettingsTempStorage::RegisterPrefs(local_state_); + } + + std::map<std::string, std::string> ref_map_; + ScopedTempDir temp_dir_; + PrefService* local_state_; +}; + +TEST_F(SignedSettingsTempStorageTest, Basic) { + EXPECT_GT(ref_map_.size(), 3u); // Number above 3 is many. + typedef std::map<std::string, std::string>::iterator It; + std::vector<It> a_list; + for (It it = ref_map_.begin(); it != ref_map_.end(); ++it) { + a_list.push_back(it); + } + std::random_shuffle(a_list.begin(), a_list.end()); + std::vector<It> b_list(a_list); + std::copy(b_list.begin(), + b_list.begin() + b_list.size() / 2, + std::back_inserter(a_list)); + std::random_shuffle(a_list.begin(), a_list.end()); + for (size_t i = 0; i < a_list.size(); ++i) { + EXPECT_TRUE(SignedSettingsTempStorage::Store(a_list[i]->first, + a_list[i]->second, + local_state_)); + } + for (int i = 0; i < 3; ++i) { + std::copy(a_list.begin(), a_list.end(), std::back_inserter(b_list)); + } + std::random_shuffle(b_list.begin(), b_list.end()); + std::string value; + for (size_t i = 0; i < b_list.size(); ++i) { + EXPECT_TRUE(SignedSettingsTempStorage::Retrieve(b_list[i]->first, &value, + local_state_)); + EXPECT_EQ(b_list[i]->second, value); + EXPECT_FALSE(SignedSettingsTempStorage::Retrieve("non-existent tv-series", + &value, + local_state_)); + } +} + +} // namespace chromeos + diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 0b65bf0..f967746 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -63,6 +63,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/cros_settings_provider_user.h" #include "chrome/browser/chromeos/login/apply_services_customization.h" +#include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/preferences.h" @@ -103,6 +104,7 @@ void RegisterLocalState(PrefService* local_state) { WizardController::RegisterPrefs(local_state); chromeos::InputMethodMenuButton::RegisterPrefs(local_state); chromeos::ApplyServicesCustomization::RegisterPrefs(local_state); + chromeos::SignedSettingsTempStorage::RegisterPrefs(local_state); #endif } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index d0c480b..0da2e82 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -620,6 +620,8 @@ 'browser/chromeos/login/signed_settings.h', 'browser/chromeos/login/signed_settings_helper.cc', 'browser/chromeos/login/signed_settings_helper.h', + 'browser/chromeos/login/signed_settings_temp_storage.cc', + 'browser/chromeos/login/signed_settings_temp_storage.h', 'browser/chromeos/login/test_attempt_state.cc', 'browser/chromeos/login/test_attempt_state.h', 'browser/chromeos/login/update_screen.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index c7b3d1c..872f3bf 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1062,6 +1062,7 @@ 'browser/chromeos/login/parallel_authenticator_unittest.cc', 'browser/chromeos/login/signed_settings_unittest.cc', 'browser/chromeos/login/signed_settings_helper_unittest.cc', + 'browser/chromeos/login/signed_settings_temp_storage_unittest.cc', 'browser/chromeos/login/wizard_accessibility_handler_unittest.cc', 'browser/chromeos/notifications/desktop_notifications_unittest.cc', 'browser/chromeos/offline/offline_load_page_unittest.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index ab52dda..e792b85 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -771,7 +771,7 @@ const char kSaveFileDefaultDirectory[] = "savefile.default_directory"; // String which specifies the last directory that was chosen for uploading // or opening a file. -extern const char kSelectFileLastDirectory[] = "selectfile.last_directory"; +const char kSelectFileLastDirectory[] = "selectfile.last_directory"; // Extensions which should be opened upon completion. const char kDownloadExtensionsToOpen[] = "download.extensions_to_open"; @@ -1028,6 +1028,12 @@ const char kRemotingHasSetupCompleted[] = "remoting.has_setup_completed"; // launches. const char kRegisteredBackgroundContents[] = "background_contents.registered"; +#if defined(OS_CHROMEOS) +// Dictionary for transient storage of settings that should go into signed +// settings storage before owner has been assigned. +const char kSignedSettingsTempStorage[] = "signed_settings_temp_storage"; +#endif + // *************** SERVICE PREFS *************** // These are attached to the service process. @@ -1041,9 +1047,9 @@ const char kCloudPrintAuthToken[] = "cloud_print.auth_token"; const char kCloudPrintXMPPAuthToken[] = "cloud_print.xmpp_auth_token"; // The email address of the account used to authenticate with the Cloud Print // server. -extern const char kCloudPrintEmail[] = "cloud_print.email"; +const char kCloudPrintEmail[] = "cloud_print.email"; // Settings specific to underlying print system. -extern const char kCloudPrintPrintSystemSettings[] = +const char kCloudPrintPrintSystemSettings[] = "cloud_print.print_system_settings"; // Used by the service process to determine if the remoting host is enabled. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 2a5d6c3..bdc2c77 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -394,6 +394,10 @@ extern const char kProxyServer[]; extern const char kProxyPacUrl[]; extern const char kProxyBypassList[]; +#if defined(OS_CHROMEOS) +extern const char kSignedSettingsTempStorage[]; +#endif + extern const char kRegisteredBackgroundContents[]; } // namespace prefs |