Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/extensions/external_pref_extension_provider.cc

Issue 5742008: Clean up threading model of external extension providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final rebase Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/external_pref_extension_provider.h"
6
7 #include "app/app_paths.h"
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "chrome/browser/browser_thread.h"
13 #include "chrome/browser/extensions/stateful_external_extension_provider.h"
14 #include "chrome/common/json_value_serializer.h"
15
16 ExternalPrefExtensionProvider::ExternalPrefExtensionProvider()
17 : StatefulExternalExtensionProvider(Extension::EXTERNAL_PREF,
18 Extension::EXTERNAL_PREF_DOWNLOAD) {
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
20 FilePath json_file;
21 PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &json_file);
22 json_file = json_file.Append(FILE_PATH_LITERAL("external_extensions.json"));
23
24 if (file_util::PathExists(json_file)) {
25 JSONFileValueSerializer serializer(json_file);
26 SetPreferences(&serializer);
27 } else {
28 set_prefs(new DictionaryValue());
29 }
30 }
31
32 ExternalPrefExtensionProvider::~ExternalPrefExtensionProvider() {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 }
35
36 void ExternalPrefExtensionProvider::SetPreferencesForTesting(
37 const std::string& json_data_for_testing) {
38 JSONStringValueSerializer serializer(json_data_for_testing);
39 SetPreferences(&serializer);
40 }
41
42 void ExternalPrefExtensionProvider::SetPreferences(
43 ValueSerializer* serializer) {
44 std::string error_msg;
45 Value* extensions = serializer->Deserialize(NULL, &error_msg);
46 scoped_ptr<DictionaryValue> dictionary(new DictionaryValue());
47 if (!extensions) {
48 LOG(WARNING) << "Unable to deserialize json data: " << error_msg;
49 } else {
50 if (!extensions->IsType(Value::TYPE_DICTIONARY)) {
51 NOTREACHED() << "Invalid json data";
52 } else {
53 dictionary.reset(static_cast<DictionaryValue*>(extensions));
54 }
55 }
56 set_prefs(dictionary.release());
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698