OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/extensions/external_pref_extension_provider.h" | 5 #include "chrome/browser/extensions/external_pref_extension_provider.h" |
6 | 6 |
7 #include "app/app_paths.h" | 7 #include "app/app_paths.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "chrome/browser/browser_thread.h" |
12 #include "chrome/browser/extensions/stateful_external_extension_provider.h" | 13 #include "chrome/browser/extensions/stateful_external_extension_provider.h" |
13 #include "chrome/common/json_value_serializer.h" | 14 #include "chrome/common/json_value_serializer.h" |
14 | 15 |
15 ExternalPrefExtensionProvider::ExternalPrefExtensionProvider() | 16 ExternalPrefExtensionProvider::ExternalPrefExtensionProvider() |
16 : StatefulExternalExtensionProvider(Extension::EXTERNAL_PREF, | 17 : StatefulExternalExtensionProvider(Extension::EXTERNAL_PREF, |
17 Extension::EXTERNAL_PREF_DOWNLOAD) { | 18 Extension::EXTERNAL_PREF_DOWNLOAD) { |
| 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
18 FilePath json_file; | 20 FilePath json_file; |
19 PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &json_file); | 21 PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &json_file); |
20 json_file = json_file.Append(FILE_PATH_LITERAL("external_extensions.json")); | 22 json_file = json_file.Append(FILE_PATH_LITERAL("external_extensions.json")); |
21 | 23 |
22 if (file_util::PathExists(json_file)) { | 24 if (file_util::PathExists(json_file)) { |
23 JSONFileValueSerializer serializer(json_file); | 25 JSONFileValueSerializer serializer(json_file); |
24 SetPreferences(&serializer); | 26 SetPreferences(&serializer); |
25 } else { | 27 } else { |
26 prefs_.reset(new DictionaryValue()); | 28 set_prefs(new DictionaryValue()); |
27 } | 29 } |
28 } | 30 } |
29 | 31 |
30 ExternalPrefExtensionProvider::~ExternalPrefExtensionProvider() { | 32 ExternalPrefExtensionProvider::~ExternalPrefExtensionProvider() { |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
31 } | 34 } |
32 | 35 |
33 void ExternalPrefExtensionProvider::SetPreferencesForTesting( | 36 void ExternalPrefExtensionProvider::SetPreferencesForTesting( |
34 const std::string& json_data_for_testing) { | 37 const std::string& json_data_for_testing) { |
35 JSONStringValueSerializer serializer(json_data_for_testing); | 38 JSONStringValueSerializer serializer(json_data_for_testing); |
36 SetPreferences(&serializer); | 39 SetPreferences(&serializer); |
37 } | 40 } |
38 | 41 |
39 void ExternalPrefExtensionProvider::SetPreferences( | 42 void ExternalPrefExtensionProvider::SetPreferences( |
40 ValueSerializer* serializer) { | 43 ValueSerializer* serializer) { |
41 std::string error_msg; | 44 std::string error_msg; |
42 Value* extensions = serializer->Deserialize(NULL, &error_msg); | 45 Value* extensions = serializer->Deserialize(NULL, &error_msg); |
43 scoped_ptr<DictionaryValue> dictionary(new DictionaryValue()); | 46 scoped_ptr<DictionaryValue> dictionary(new DictionaryValue()); |
44 if (!extensions) { | 47 if (!extensions) { |
45 LOG(WARNING) << "Unable to deserialize json data: " << error_msg; | 48 LOG(WARNING) << "Unable to deserialize json data: " << error_msg; |
46 } else { | 49 } else { |
47 if (!extensions->IsType(Value::TYPE_DICTIONARY)) { | 50 if (!extensions->IsType(Value::TYPE_DICTIONARY)) { |
48 NOTREACHED() << "Invalid json data"; | 51 NOTREACHED() << "Invalid json data"; |
49 } else { | 52 } else { |
50 dictionary.reset(static_cast<DictionaryValue*>(extensions)); | 53 dictionary.reset(static_cast<DictionaryValue*>(extensions)); |
51 } | 54 } |
52 } | 55 } |
53 prefs_.reset(dictionary.release()); | 56 set_prefs(dictionary.release()); |
54 } | 57 } |
OLD | NEW |