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

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

Issue 9963120: Introduces an additional extension loader that load extra extensions based on per-extension json fi… (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/bind.h"
6 #include "base/dir_reader_posix.h"
7 #include "base/file_path.h"
8 #include "base/file_util.h"
9 #include "base/json/json_file_value_serializer.h"
10 #include "base/json/json_string_value_serializer.h"
11 #include "base/memory/scoped_handle.h"
12 #include "base/path_service.h"
13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h"
15 #include "base/values.h"
16 #include "base/version.h"
17 #include "chrome/browser/extensions/external_extension_provider_impl.h"
18 #include "chrome/browser/extensions/external_extension_util.h"
19 #include "chrome/browser/extensions/external_filesystem_extension_loader_linux.h "
20 #include "content/public/browser/browser_thread.h"
21
22 using content::BrowserThread;
23
24 namespace {
25
26 std::set<FilePath> GetPrefsCandidateFilesFromFolder(
27 const FilePath& external_extension_search_path) {
28 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
29
30 std::set<FilePath> external_extension_paths;
31
32 if (!file_util::PathExists(external_extension_search_path)) {
33 // Does not have to exist.
34 return external_extension_paths;
35 }
36
37 base::DirReaderPosix
38 reader(external_extension_search_path.value().c_str());
39
40 if (!reader.IsValid()) {
41 LOG(ERROR) << "Can not read external extensions path '"
42 << external_extension_search_path.LossyDisplayName()
43 << "' although it appears to exist.";
44 return external_extension_paths;
45 }
46
47 while (reader.Next()) {
48 const FilePath filename(reader.name());
49
50 if (filename.MatchesExtension(".json")) {
51 external_extension_paths.insert(filename);
52 } else {
53 DVLOG(1) << "Not considering: " << reader.name()
54 << " (does not have a .json extension)";
55 }
56 }
57
58 return external_extension_paths;
59 }
60
61 } // namespace
62
63 ExternalFilesystemExtensionLoader::ExternalFilesystemExtensionLoader(
64 int base_path_key)
65 : base_path_key_(base_path_key) {
66 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 }
68
69 ExternalFilesystemExtensionLoader::~ExternalFilesystemExtensionLoader()
70 {}
Finnur 2012/04/25 13:33:45 We prefer: func() { } over func() {} Also, wh
Alexandre Abreu 2012/04/25 15:31:05 Done.
71
72 void ExternalFilesystemExtensionLoader::StartLoading() {
73 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
74 BrowserThread::PostTask(
75 BrowserThread::FILE, FROM_HERE,
76 base::Bind(&ExternalFilesystemExtensionLoader::LoadOnFileThread, this));
77 }
78
79 const FilePath ExternalFilesystemExtensionLoader::GetBaseCrxFilePath() {
Finnur 2012/04/25 13:33:45 Um... where is this function used and why is it im
Alexandre Abreu 2012/04/25 15:31:05 it is used in external_extension_provider_impl.cc,
80 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
81
82 // |extension_base_path_| was set in LoadOnFileThread().
83 return extension_base_path_;
84 }
85
86 void ExternalFilesystemExtensionLoader::LoadOnFileThread() {
87 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
88 scoped_ptr<DictionaryValue> prefs(new DictionaryValue);
89
90 if (!PathService::Get(base_path_key_,
91 &extension_base_path_)) {
92 DVLOG(1) << "Could not retrieve per-extension search path";
93 return;
94 }
95
96 // First list the potential .json candidates.
97 std::set<FilePath>
98 candidates = GetPrefsCandidateFilesFromFolder(extension_base_path_);
99 if (candidates.empty()) {
100 DVLOG(1) << "Extension candidates list empty";
101 return;
102 }
103
104 // For each file read the json description & build the proper
105 // associated prefs.
106 FilePath extension_search_path = extension_base_path_;
107 for (std::set<FilePath>::const_iterator it = candidates.begin();
108 it != candidates.end();
109 ++it) {
110 FilePath extension_candidate_path =
111 extension_search_path.Append(*it);
112
113 FilePath::StringType id =
114 extension_candidate_path.RemoveExtension().BaseName().value();
115
116 DVLOG(1) << "Reading json file: " << extension_candidate_path.value();
117
118 JSONFileValueSerializer serializer(extension_candidate_path);
119 DictionaryValue* json_file_content =
120 ExternalExtensionUtil::ExtractExtensionPrefs(extension_candidate_path,
121 &serializer);
Finnur 2012/04/25 13:33:45 When splitting arguments between lines, we prefer:
Alexandre Abreu 2012/04/25 15:31:05 Done.
122
123 if (NULL != json_file_content) {
124 DVLOG(1) << "Adding extension with id: " << id;
125
126 prefs->Set(id, json_file_content);
127 }
128 }
129
130 prefs_.reset(prefs.release());
131 BrowserThread::PostTask(
132 BrowserThread::UI, FROM_HERE,
133 base::Bind(&ExternalFilesystemExtensionLoader::LoadFinished, this));
134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698