diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 15:01:35 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 15:01:35 +0000 |
commit | ea587b01337fd38626923e48258a2b39a631543a (patch) | |
tree | 944b56193e7870f97877836e490556b0983f5b0a /chrome/browser | |
parent | 893934384f65e8676d226396c34625880a46436a (diff) | |
download | chromium_src-ea587b01337fd38626923e48258a2b39a631543a.zip chromium_src-ea587b01337fd38626923e48258a2b39a631543a.tar.gz chromium_src-ea587b01337fd38626923e48258a2b39a631543a.tar.bz2 |
Removed dependency on ChromeThread from JsonPrefStore and moved JsonPrefStore and PrefStore to chrome/common. This is because JsonPrefStore is needed in the service process
BUG=None.
TEST=Updated unit-tests
Review URL: http://codereview.chromium.org/2066015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47915 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_main.cc | 7 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 7 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_pref_store.h | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui_uitest.cc | 8 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler_unittest.cc | 13 | ||||
-rw-r--r-- | chrome/browser/dummy_pref_store.h | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/extensions/test_extension_prefs.cc | 8 | ||||
-rw-r--r-- | chrome/browser/json_pref_store.cc | 131 | ||||
-rw-r--r-- | chrome/browser/json_pref_store.h | 48 | ||||
-rw-r--r-- | chrome/browser/json_pref_store_unittest.cc | 148 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service_uitest.cc | 8 | ||||
-rw-r--r-- | chrome/browser/pref_service.h | 2 | ||||
-rw-r--r-- | chrome/browser/pref_store.h | 48 | ||||
-rw-r--r-- | chrome/browser/privacy_blacklist/blacklist_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 7 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_unittest.cc | 6 |
17 files changed, 63 insertions, 397 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 4f69109..acc4525 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -40,7 +40,6 @@ #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/first_run.h" #include "chrome/browser/jankometer.h" -#include "chrome/browser/json_pref_store.h" #include "chrome/browser/metrics/histogram_synchronizer.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/dns_global.h" @@ -61,6 +60,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/json_pref_store.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/main_function_params.h" #include "chrome/common/net/net_resource_provider.h" @@ -440,7 +440,10 @@ PrefService* InitializeLocalState(const CommandLine& parsed_command_line, parsed_command_line.HasSwitch(switches::kParentProfile)) { FilePath parent_profile = parsed_command_line.GetSwitchValuePath(switches::kParentProfile); - PrefService parent_local_state(new JsonPrefStore(parent_profile)); + PrefService parent_local_state( + new JsonPrefStore( + parent_profile, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE))); parent_local_state.RegisterStringPref(prefs::kApplicationLocale, std::wstring()); // Right now, we only inherit the locale setting from the parent profile. diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index f630571..e6f99a1 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -30,7 +30,6 @@ #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/io_thread.h" -#include "chrome/browser/json_pref_store.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h" @@ -49,6 +48,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/extensions/extension_l10n_util.h" +#include "chrome/common/json_pref_store.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" @@ -408,7 +408,10 @@ void BrowserProcessImpl::CreateLocalState() { FilePath local_state_path; PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); - local_state_.reset(new PrefService(new JsonPrefStore(local_state_path))); + local_state_.reset(new PrefService( + new JsonPrefStore( + local_state_path, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)))); } void BrowserProcessImpl::CreateIconManager() { diff --git a/chrome/browser/configuration_policy_pref_store.h b/chrome/browser/configuration_policy_pref_store.h index 8335070..b01b429 100644 --- a/chrome/browser/configuration_policy_pref_store.h +++ b/chrome/browser/configuration_policy_pref_store.h @@ -11,7 +11,7 @@ #include "base/scoped_ptr.h" #include "base/values.h" #include "chrome/browser/configuration_policy_store.h" -#include "chrome/browser/pref_store.h" +#include "chrome/common/pref_store.h" #include "testing/gtest/include/gtest/gtest_prod.h" class ConfigurationPolicyProvider; diff --git a/chrome/browser/dom_ui/new_tab_ui_uitest.cc b/chrome/browser/dom_ui/new_tab_ui_uitest.cc index 2014942..eebdc45 100644 --- a/chrome/browser/dom_ui/new_tab_ui_uitest.cc +++ b/chrome/browser/dom_ui/new_tab_ui_uitest.cc @@ -6,9 +6,10 @@ #include "base/file_path.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/new_tab_ui.h" -#include "chrome/browser/json_pref_store.h" #include "chrome/browser/pref_service.h" +#include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/tab_proxy.h" @@ -71,7 +72,10 @@ TEST_F(NewTabUITest, ChromeInternalLoadsNTP) { } TEST_F(NewTabUITest, UpdateUserPrefsVersion) { - PrefService prefs(new JsonPrefStore(FilePath())); + PrefService prefs( + new JsonPrefStore( + FilePath(), + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE))); // Does the migration NewTabUI::RegisterUserPrefs(&prefs); diff --git a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc index 08f3406..48530d2 100644 --- a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc +++ b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc @@ -6,8 +6,9 @@ #include "base/file_path.h" #include "base/scoped_ptr.h" -#include "chrome/browser/json_pref_store.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/pref_service.h" +#include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "testing/gtest/include/gtest/gtest.h" @@ -15,7 +16,10 @@ class ShownSectionsHandlerTest : public testing::Test { }; TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { - PrefService pref(new JsonPrefStore(FilePath())); + PrefService pref( + new JsonPrefStore( + FilePath(), + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE))); // Set an *old* value pref.RegisterIntegerPref(prefs::kNTPShownSections, 0); @@ -33,7 +37,10 @@ TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { } TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs1To2) { - PrefService pref(new JsonPrefStore(FilePath())); + PrefService pref( + new JsonPrefStore( + FilePath(), + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE))); // Set an *old* value pref.RegisterIntegerPref(prefs::kNTPShownSections, 0); diff --git a/chrome/browser/dummy_pref_store.h b/chrome/browser/dummy_pref_store.h index ed3da44..a3c1ee4 100644 --- a/chrome/browser/dummy_pref_store.h +++ b/chrome/browser/dummy_pref_store.h @@ -6,7 +6,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" -#include "chrome/browser/pref_store.h" +#include "chrome/common/pref_store.h" class DummyPrefStore : public PrefStore { public: diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 78264b3..c74b644 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -18,6 +18,7 @@ #include "base/string_util.h" #include "base/task.h" #include "base/version.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_creator.h" #include "chrome/browser/extensions/extension_error_reporter.h" @@ -241,7 +242,11 @@ ExtensionsServiceTestBase::~ExtensionsServiceTestBase() { void ExtensionsServiceTestBase::InitializeExtensionsService( const FilePath& pref_file, const FilePath& extensions_install_dir) { ExtensionTestingProfile* profile = new ExtensionTestingProfile(); - prefs_.reset(new PrefService(new JsonPrefStore(pref_file))); + prefs_.reset(new PrefService( + new JsonPrefStore( + pref_file, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)))); + Profile::RegisterUserPrefs(prefs_.get()); browser::RegisterUserPrefs(prefs_.get()); profile_.reset(profile); diff --git a/chrome/browser/extensions/test_extension_prefs.cc b/chrome/browser/extensions/test_extension_prefs.cc index e9a1472..716539f 100644 --- a/chrome/browser/extensions/test_extension_prefs.cc +++ b/chrome/browser/extensions/test_extension_prefs.cc @@ -9,10 +9,10 @@ #include "base/message_loop.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/extensions/extension_prefs.h" -#include "chrome/browser/json_pref_store.h" #include "chrome/browser/pref_service.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" +#include "chrome/common/json_pref_store.h" #include "testing/gtest/include/gtest/gtest.h" TestExtensionPrefs::TestExtensionPrefs() { @@ -37,7 +37,11 @@ void TestExtensionPrefs::RecreateExtensionPrefs() { file_loop.RunAllPending(); } - pref_service_.reset(new PrefService(new JsonPrefStore(preferences_file_))); + pref_service_.reset(new PrefService( + new JsonPrefStore( + preferences_file_, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)))); + ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); prefs_.reset(new ExtensionPrefs(pref_service_.get(), temp_dir_.path())); } diff --git a/chrome/browser/json_pref_store.cc b/chrome/browser/json_pref_store.cc deleted file mode 100644 index 40fd309..0000000 --- a/chrome/browser/json_pref_store.cc +++ /dev/null @@ -1,131 +0,0 @@ -// 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/json_pref_store.h" - -#include <algorithm> - -#include "base/file_util.h" -#include "base/values.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/common/json_value_serializer.h" - -namespace { - -// Some extensions we'll tack on to copies of the Preferences files. -const FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad"); - -} // namespace - -JsonPrefStore::JsonPrefStore(const FilePath& filename) - : path_(filename), - prefs_(new DictionaryValue()), - read_only_(false), - writer_(filename, - ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)) { -} - -JsonPrefStore::~JsonPrefStore() { - if (writer_.HasPendingWrite() && !read_only_) - writer_.DoScheduledWrite(); -} - -PrefStore::PrefReadError JsonPrefStore::ReadPrefs() { - JSONFileValueSerializer serializer(path_); - - int error_code = 0; - std::string error_msg; - scoped_ptr<Value> value(serializer.Deserialize(&error_code, &error_msg)); - if (!value.get()) { -#if defined(GOOGLE_CHROME_BUILD) - // This log could be used for more detailed client-side error diagnosis, - // but since this triggers often with unit tests, we need to disable it - // in non-official builds. - PLOG(ERROR) << "Error reading Preferences: " << error_msg << " " << - path_.value(); -#endif - PrefReadError error; - switch (error_code) { - case JSONFileValueSerializer::JSON_ACCESS_DENIED: - // If the file exists but is simply unreadable, put the file into a - // state where we don't try to save changes. Otherwise, we could - // clobber the existing prefs. - error = PREF_READ_ERROR_ACCESS_DENIED; - read_only_ = true; - break; - case JSONFileValueSerializer::JSON_CANNOT_READ_FILE: - error = PREF_READ_ERROR_FILE_OTHER; - read_only_ = true; - break; - case JSONFileValueSerializer::JSON_FILE_LOCKED: - error = PREF_READ_ERROR_FILE_LOCKED; - read_only_ = true; - break; - case JSONFileValueSerializer::JSON_NO_SUCH_FILE: - // If the file just doesn't exist, maybe this is first run. In any case - // there's no harm in writing out default prefs in this case. - error = PREF_READ_ERROR_NO_FILE; - break; - default: - error = PREF_READ_ERROR_JSON_PARSE; - // JSON errors indicate file corruption of some sort. - // Since the file is corrupt, move it to the side and continue with - // empty preferences. This will result in them losing their settings. - // We keep the old file for possible support and debugging assistance - // as well as to detect if they're seeing these errors repeatedly. - // TODO(erikkay) Instead, use the last known good file. - FilePath bad = path_.ReplaceExtension(kBadExtension); - - // If they've ever had a parse error before, put them in another bucket. - // TODO(erikkay) if we keep this error checking for very long, we may - // want to differentiate between recent and long ago errors. - if (file_util::PathExists(bad)) - error = PREF_READ_ERROR_JSON_REPEAT; - file_util::Move(path_, bad); - break; - } - return error; - } - - // Preferences should always have a dictionary root. - if (!value->IsType(Value::TYPE_DICTIONARY)) { - // See comment for the default case above. - read_only_ = true; - return PREF_READ_ERROR_JSON_TYPE; - } - - prefs_.reset(static_cast<DictionaryValue*>(value.release())); - - return PREF_READ_ERROR_NONE; -} - -bool JsonPrefStore::WritePrefs() { - std::string data; - if (!SerializeData(&data)) - return false; - - // Lie about our ability to save. - if (read_only_) - return true; - - writer_.WriteNow(data); - return true; -} - -void JsonPrefStore::ScheduleWritePrefs() { - if (read_only_) - return; - - writer_.ScheduleWrite(this); -} - -bool JsonPrefStore::SerializeData(std::string* output) { - // TODO(tc): Do we want to prune webkit preferences that match the default - // value? - JSONStringValueSerializer serializer(output); - serializer.set_pretty_print(true); - scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); - return serializer.Serialize(*(copy.get())); -} - diff --git a/chrome/browser/json_pref_store.h b/chrome/browser/json_pref_store.h deleted file mode 100644 index e25d310..0000000 --- a/chrome/browser/json_pref_store.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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_JSON_PREF_STORE_H_ -#define CHROME_BROWSER_JSON_PREF_STORE_H_ - -#include <string> - -#include "base/scoped_ptr.h" -#include "chrome/browser/pref_store.h" -#include "chrome/common/important_file_writer.h" - -class DictionaryValue; -class FilePath; - -class JsonPrefStore : public PrefStore, - public ImportantFileWriter::DataSerializer { - public: - explicit JsonPrefStore(const FilePath& pref_filename); - virtual ~JsonPrefStore(); - - // PrefStore methods: - virtual bool ReadOnly() { return read_only_; } - - virtual DictionaryValue* prefs() { return prefs_.get(); } - - virtual PrefReadError ReadPrefs(); - - virtual bool WritePrefs(); - - virtual void ScheduleWritePrefs(); - - // ImportantFileWriter::DataSerializer methods: - virtual bool SerializeData(std::string* data); - - private: - FilePath path_; - - scoped_ptr<DictionaryValue> prefs_; - - bool read_only_; - - // Helper for safely writing pref data. - ImportantFileWriter writer_; -}; - -#endif // CHROME_BROWSER_JSON_PREF_STORE_H_ diff --git a/chrome/browser/json_pref_store_unittest.cc b/chrome/browser/json_pref_store_unittest.cc deleted file mode 100644 index de22695..0000000 --- a/chrome/browser/json_pref_store_unittest.cc +++ /dev/null @@ -1,148 +0,0 @@ -// 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 "app/test/data/resource.h" -#include "base/file_util.h" -#include "base/message_loop.h" -#include "base/path_service.h" -#include "base/scoped_ptr.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/json_pref_store.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/pref_names.h" -#include "testing/gtest/include/gtest/gtest.h" - -class JsonPrefStoreTest : public testing::Test { - protected: - virtual void SetUp() { - // Name a subdirectory of the temp directory. - ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); - test_dir_ = test_dir_.AppendASCII("JsonPrefStoreTest"); - - // Create a fresh, empty copy of this directory. - file_util::Delete(test_dir_, true); - file_util::CreateDirectory(test_dir_); - - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); - data_dir_ = data_dir_.AppendASCII("pref_service"); - ASSERT_TRUE(file_util::PathExists(data_dir_)); - } - - virtual void TearDown() { - // Clean up test directory - ASSERT_TRUE(file_util::Delete(test_dir_, true)); - ASSERT_FALSE(file_util::PathExists(test_dir_)); - } - - // the path to temporary directory used to contain the test operations - FilePath test_dir_; - // the path to the directory where the test data is stored - FilePath data_dir_; -}; - -// Test fallback behavior for a nonexistent file. -TEST_F(JsonPrefStoreTest, NonExistentFile) { - FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); - ASSERT_FALSE(file_util::PathExists(bogus_input_file)); - JsonPrefStore pref_store(bogus_input_file); - EXPECT_EQ(PrefStore::PREF_READ_ERROR_NO_FILE, pref_store.ReadPrefs()); - EXPECT_FALSE(pref_store.ReadOnly()); - EXPECT_TRUE(pref_store.prefs()->empty()); -} - -// Test fallback behavior for an invalid file. -TEST_F(JsonPrefStoreTest, InvalidFile) { - FilePath invalid_file_original = data_dir_.AppendASCII("invalid.json"); - FilePath invalid_file = test_dir_.AppendASCII("invalid.json"); - ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file)); - JsonPrefStore pref_store(invalid_file); - EXPECT_EQ(PrefStore::PREF_READ_ERROR_JSON_PARSE, pref_store.ReadPrefs()); - EXPECT_FALSE(pref_store.ReadOnly()); - EXPECT_TRUE(pref_store.prefs()->empty()); - - // The file should have been moved aside. - EXPECT_FALSE(file_util::PathExists(invalid_file)); - FilePath moved_aside = test_dir_.AppendASCII("invalid.bad"); - EXPECT_TRUE(file_util::PathExists(moved_aside)); - EXPECT_TRUE(file_util::TextContentsEqual(invalid_file_original, - moved_aside)); -} - -TEST_F(JsonPrefStoreTest, Basic) { - ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"), - test_dir_.AppendASCII("write.json"))); - - // Test that the persistent value can be loaded. - FilePath input_file = test_dir_.AppendASCII("write.json"); - ASSERT_TRUE(file_util::PathExists(input_file)); - JsonPrefStore pref_store(input_file); - ASSERT_EQ(PrefStore::PREF_READ_ERROR_NONE, pref_store.ReadPrefs()); - ASSERT_FALSE(pref_store.ReadOnly()); - DictionaryValue* prefs = pref_store.prefs(); - - // The JSON file looks like this: - // { - // "homepage": "http://www.cnn.com", - // "some_directory": "/usr/local/", - // "tabs": { - // "new_windows_in_tabs": true, - // "max_tabs": 20 - // } - // } - - const wchar_t kNewWindowsInTabs[] = L"tabs.new_windows_in_tabs"; - const wchar_t kMaxTabs[] = L"tabs.max_tabs"; - const wchar_t kLongIntPref[] = L"long_int.pref"; - - std::wstring cnn(L"http://www.cnn.com"); - - std::wstring string_value; - EXPECT_TRUE(prefs->GetString(prefs::kHomePage, &string_value)); - EXPECT_EQ(cnn, string_value); - - const wchar_t kSomeDirectory[] = L"some_directory"; - - FilePath::StringType path; - EXPECT_TRUE(prefs->GetString(kSomeDirectory, &path)); - EXPECT_EQ(FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")), path); - FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/")); - prefs->SetString(kSomeDirectory, some_path.value()); - EXPECT_TRUE(prefs->GetString(kSomeDirectory, &path)); - EXPECT_EQ(some_path.value(), path); - - // Test reading some other data types from sub-dictionaries. - bool boolean; - EXPECT_TRUE(prefs->GetBoolean(kNewWindowsInTabs, &boolean)); - EXPECT_TRUE(boolean); - - prefs->SetBoolean(kNewWindowsInTabs, false); - EXPECT_TRUE(prefs->GetBoolean(kNewWindowsInTabs, &boolean)); - EXPECT_FALSE(boolean); - - int integer; - EXPECT_TRUE(prefs->GetInteger(kMaxTabs, &integer)); - EXPECT_EQ(20, integer); - prefs->SetInteger(kMaxTabs, 10); - EXPECT_TRUE(prefs->GetInteger(kMaxTabs, &integer)); - EXPECT_EQ(10, integer); - - prefs->SetString(kLongIntPref, Int64ToWString(214748364842LL)); - EXPECT_TRUE(prefs->GetString(kLongIntPref, &string_value)); - EXPECT_EQ(214748364842LL, StringToInt64(WideToUTF16Hack(string_value))); - - // Serialize and compare to expected output. - // SavePersistentPrefs uses ImportantFileWriter which needs a file thread. - MessageLoop message_loop; - ChromeThread file_thread(ChromeThread::FILE, &message_loop); - FilePath output_file = input_file; - FilePath golden_output_file = data_dir_.AppendASCII("write.golden.json"); - ASSERT_TRUE(file_util::PathExists(golden_output_file)); - ASSERT_TRUE(pref_store.WritePrefs()); - MessageLoop::current()->RunAllPending(); - EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file)); - ASSERT_TRUE(file_util::Delete(output_file, false)); -} diff --git a/chrome/browser/metrics/metrics_service_uitest.cc b/chrome/browser/metrics/metrics_service_uitest.cc index a943c68..05c1b8d 100644 --- a/chrome/browser/metrics/metrics_service_uitest.cc +++ b/chrome/browser/metrics/metrics_service_uitest.cc @@ -11,10 +11,11 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/platform_thread.h" -#include "chrome/browser/json_pref_store.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/pref_service.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/test/automation/tab_proxy.h" @@ -52,7 +53,10 @@ class MetricsServiceTest : public UITest { FilePath local_state_path = user_data_dir() .Append(chrome::kLocalStateFilename); - return new PrefService(new JsonPrefStore(local_state_path)); + return new PrefService( + new JsonPrefStore( + local_state_path, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE))); } }; diff --git a/chrome/browser/pref_service.h b/chrome/browser/pref_service.h index 4f660ee..c79edd7 100644 --- a/chrome/browser/pref_service.h +++ b/chrome/browser/pref_service.h @@ -15,7 +15,7 @@ #include "base/observer_list.h" #include "base/scoped_ptr.h" #include "base/values.h" -#include "chrome/browser/pref_store.h" +#include "chrome/common/pref_store.h" class NotificationObserver; class Preference; diff --git a/chrome/browser/pref_store.h b/chrome/browser/pref_store.h deleted file mode 100644 index 9f72631..0000000 --- a/chrome/browser/pref_store.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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_PREF_STORE_H_ -#define CHROME_BROWSER_PREF_STORE_H_ - -class DictionaryValue; - -// This is an abstract interface for reading and writing from/to a persistent -// preference store, used by |PrefService|. An implementation using a JSON file -// can be found in |JsonPrefStore|, while an implementation without any backing -// store (currently used for testing) can be found in |DummyPrefStore|. -class PrefStore { - public: - // Unique integer code for each type of error so we can report them - // distinctly in a histogram. - // NOTE: Don't change the order here as it will change the server's meaning - // of the histogram. - enum PrefReadError { - PREF_READ_ERROR_NONE = 0, - PREF_READ_ERROR_JSON_PARSE, - PREF_READ_ERROR_JSON_TYPE, - PREF_READ_ERROR_ACCESS_DENIED, - PREF_READ_ERROR_FILE_OTHER, - PREF_READ_ERROR_FILE_LOCKED, - PREF_READ_ERROR_NO_FILE, - PREF_READ_ERROR_JSON_REPEAT, - PREF_READ_ERROR_OTHER - }; - - virtual ~PrefStore() { } - - // Whether the store is in a pseudo-read-only mode where changes are not - // actually persisted to disk. This happens in some cases when there are - // read errors during startup. - virtual bool ReadOnly() { return true; } - - virtual DictionaryValue* prefs() = 0; - - virtual PrefReadError ReadPrefs() = 0; - - virtual bool WritePrefs() { return true; } - - virtual void ScheduleWritePrefs() { } -}; - -#endif // CHROME_BROWSER_PREF_STORE_H_ diff --git a/chrome/browser/privacy_blacklist/blacklist_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_unittest.cc index a7a3188..049c32d 100644 --- a/chrome/browser/privacy_blacklist/blacklist_unittest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_unittest.cc @@ -9,10 +9,11 @@ #include "base/path_service.h" #include "base/string_util.h" #include "chrome/browser/browser_prefs.h" -#include "chrome/browser/json_pref_store.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/json_pref_store.h" #include "testing/gtest/include/gtest/gtest.h" class BlacklistTest : public testing::Test { @@ -23,7 +24,10 @@ class BlacklistTest : public testing::Test { source_path = source_path.AppendASCII("profiles") .AppendASCII("blacklist_prefs").AppendASCII("Preferences"); - prefs_.reset(new PrefService(new JsonPrefStore(source_path))); + prefs_.reset(new PrefService( + new JsonPrefStore( + source_path, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)))); Profile::RegisterUserPrefs(prefs_.get()); browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); } diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index c03553f..1a01523 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -41,7 +41,6 @@ #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/in_process_webkit/webkit_context.h" -#include "chrome/browser/json_pref_store.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/ssl_config_service_manager.h" #include "chrome/browser/notifications/desktop_notification_service.h" @@ -68,6 +67,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/json_pref_store.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -987,7 +987,10 @@ net::TransportSecurityState* PrefService* ProfileImpl::GetPrefs() { if (!prefs_.get()) { - prefs_.reset(new PrefService(new JsonPrefStore(GetPrefFilePath()))); + prefs_.reset(new PrefService( + new JsonPrefStore( + GetPrefFilePath(), + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)))); // The Profile class and ProfileManager class may read some prefs so // register known prefs as soon as possible. diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc index f9e731e..e479cd3 100644 --- a/chrome/browser/tab_contents/web_contents_unittest.cc +++ b/chrome/browser/tab_contents/web_contents_unittest.cc @@ -51,7 +51,11 @@ class TabContentsTestingProfile : public TestingProfile { source_path = source_path.AppendASCII("profiles") .AppendASCII("chrome_prefs").AppendASCII("Preferences"); - prefs_.reset(new PrefService(new JsonPrefStore(source_path))); + prefs_.reset(new PrefService( + new JsonPrefStore( + source_path, + ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)))); + Profile::RegisterUserPrefs(prefs_.get()); browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); } |