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

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

Issue 10179002: Create an external source for extensions on linux that meets the needs of package managers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 | Annotate | Revision Log
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
Finnur 2012/04/24 13:03:24 nit: remove extra linebreak.
Alexandre Abreu 2012/04/24 19:30:30 Done.
23 using content::BrowserThread;
24
25 namespace {
26
27 bool HasValidJsonExtension(const FilePath & filepath) {
28 return filepath.Extension() == FilePath::StringType(".json");
29 }
Finnur 2012/04/24 13:03:24 I believe this is not needed, see FilePath::Matche
Alexandre Abreu 2012/04/24 19:30:30 Done.
30
31 DictionaryValue* ReadJsonPrefsFile(const FilePath & json_file) {
Finnur 2012/04/24 13:03:24 nit: No space before &
Finnur 2012/04/24 13:03:24 Actually, is there a reason to create a helper aro
Alexandre Abreu 2012/04/24 19:30:30 Done.
32 JSONFileValueSerializer serializer(json_file);
33 DictionaryValue*
34 json_prefs = ExternalExtensionUtil::ExtractPrefs(json_file, &serializer);
35
36 return json_prefs;
37 }
38
39 std::set<FilePath> GetPrefsCandidatesFilesFromFolder(
Finnur 2012/04/24 13:03:24 nit: s/Candidates/Candidate/ Also, my personal pre
Alexandre Abreu 2012/04/24 19:30:30 Done.
40 const FilePath& external_extension_search_path) {
41 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
42
43 std::set<FilePath> external_extension_paths;
44
45 if (!file_util::PathExists(external_extension_search_path)) {
46 // Does not have to exist.
47 DVLOG(1) << "Extension search path not found";
Finnur 2012/04/24 13:03:24 Do we need to log this? It seems like a normal con
Alexandre Abreu 2012/04/24 19:30:30 Done.
48 return external_extension_paths;
49 }
50
51 base::DirReaderPosix
52 reader(external_extension_search_path.value().c_str());
53
54 if (!reader.IsValid()) {
55 LOG(ERROR) << "Can not read external extensions path '"
56 << external_extension_search_path.LossyDisplayName()
57 << "' although it appears to exist.";
58 return external_extension_paths;
59 }
60
61 while (reader.Next()) {
62 const FilePath filename(reader.name());
63
64 DVLOG(1) << "Checking for file: " << reader.name();
Finnur 2012/04/24 13:03:24 This seems like a normal condition that we don't n
Alexandre Abreu 2012/04/24 19:30:30 Done.
65
66 if (HasValidJsonExtension(filename)) {
67 external_extension_paths.insert(filename);
68 } else {
69 DVLOG(1) << "Not considering: " << reader.name()
70 << " (does not have a .json extension)";
71 }
72 }
73
74 return external_extension_paths;
75 }
76
77 } // namespace
78
79 ExternalFilesystemExtensionLoader::ExternalFilesystemExtensionLoader(
80 int base_path_key)
81 : base_path_key_(base_path_key) {
Finnur 2012/04/24 13:03:24 nit: Indentation should be 4 spaces, not 2.
Alexandre Abreu 2012/04/24 19:30:30 Done.
82 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 }
84
85 void ExternalFilesystemExtensionLoader::StartLoading() {
86 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
87 BrowserThread::PostTask(
88 BrowserThread::FILE, FROM_HERE,
89 base::Bind(&ExternalFilesystemExtensionLoader::LoadOnFileThread, this));
90 }
91
92 void ExternalFilesystemExtensionLoader::LoadOnFileThread() {
93 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
94 scoped_ptr<DictionaryValue> prefs(new DictionaryValue);
95
96 FilePath extension_search_path;
97 if (!PathService::Get(base_path_key_,
98 &extension_search_path)) {
99 DVLOG(1) << "Could not retrieve per-extension search path";
100 return;
101 }
102
103 // First list the potential .json candidates
104 std::set<FilePath>
105 candidates = GetPrefsCandidatesFilesFromFolder(extension_search_path);
106 if (candidates.empty()) {
107 DVLOG(1) << "Extension candidates list empty";
108 return;
109 }
110
111 // For each file read the json description & build the proper
112 // associated prefs
Finnur 2012/04/24 13:03:24 nit: extra space at front. And you should in gener
Alexandre Abreu 2012/04/24 19:30:30 Done.
113 for (std::set<FilePath>::const_iterator it = candidates.begin();
114 it != candidates.end();
115 ++it) {
116 FilePath
117 extension_candidate_path = extension_search_path.Append(*it);
118
119 FilePath::StringType
120 id = extension_candidate_path.RemoveExtension().BaseName().value();
121
122 DictionaryValue*
123 json_file_content = ReadJsonPrefsFile(extension_candidate_path);
Finnur 2012/04/24 13:03:24 We prefer foo bar = function(); over foo
Alexandre Abreu 2012/04/24 19:30:30 Done.
124
125 DVLOG(1) << "Reading json file: " << extension_candidate_path.value();
126
127 if (NULL != json_file_content) {
128 DVLOG(1) << "Adding extension with id: " << id;
Finnur 2012/04/24 13:03:24 This seems like a bit too much logging to me...
Alexandre Abreu 2012/04/24 19:30:30 I removed some, for this particular one it is kind
129
130 prefs->Set(id, json_file_content);
131 }
Finnur 2012/04/24 13:03:24 If you remove the log you can remove the braces (n
Alexandre Abreu 2012/04/24 19:30:30 Done.
132 }
133
134 prefs_.reset(prefs.release());
135 BrowserThread::PostTask(
136 BrowserThread::UI, FROM_HERE,
137 base::Bind(&ExternalFilesystemExtensionLoader::LoadFinished, this));
138 }
139
140
Finnur 2012/04/24 13:03:24 nit: Extra linebreak at end.
Alexandre Abreu 2012/04/24 19:30:30 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698