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