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

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

Issue 13315: Move file enumeration to filepaths. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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
« no previous file with comments | « base/file_util_win.cc ('k') | chrome/browser/greasemonkey_master.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/extensions_service.h" 5 #include "chrome/browser/extensions/extensions_service.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/thread.h" 10 #include "base/thread.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 65
66 // ExtensionsServicesBackend 66 // ExtensionsServicesBackend
67 67
68 bool ExtensionsServiceBackend::LoadExtensionsFromDirectory( 68 bool ExtensionsServiceBackend::LoadExtensionsFromDirectory(
69 const FilePath& path, 69 const FilePath& path,
70 scoped_refptr<ExtensionsServiceFrontendInterface> frontend) { 70 scoped_refptr<ExtensionsServiceFrontendInterface> frontend) {
71 // Find all child directories in the install directory and load their 71 // Find all child directories in the install directory and load their
72 // manifests. Post errors and results to the frontend. 72 // manifests. Post errors and results to the frontend.
73 scoped_ptr<ExtensionList> extensions(new ExtensionList); 73 scoped_ptr<ExtensionList> extensions(new ExtensionList);
74 file_util::FileEnumerator enumerator(path.ToWStringHack(), 74 file_util::FileEnumerator enumerator(path,
75 false, // not recursive 75 false, // not recursive
76 file_util::FileEnumerator::DIRECTORIES); 76 file_util::FileEnumerator::DIRECTORIES);
77 for (std::wstring child_path = enumerator.Next(); !child_path.empty(); 77 for (FilePath child_path = enumerator.Next(); !child_path.value().empty();
78 child_path = enumerator.Next()) { 78 child_path = enumerator.Next()) {
79 FilePath manifest_path = FilePath::FromWStringHack(child_path).Append( 79 FilePath manifest_path = child_path.Append(Extension::kManifestFilename);
80 Extension::kManifestFilename);
81 if (!file_util::PathExists(manifest_path)) { 80 if (!file_util::PathExists(manifest_path)) {
82 ReportExtensionLoadError(frontend.get(), child_path, 81 ReportExtensionLoadError(frontend.get(), child_path.ToWStringHack(),
83 Extension::kInvalidManifestError); 82 Extension::kInvalidManifestError);
84 continue; 83 continue;
85 } 84 }
86 85
87 JSONFileValueSerializer serializer(manifest_path.ToWStringHack()); 86 JSONFileValueSerializer serializer(manifest_path.ToWStringHack());
88 Value* root = NULL; 87 Value* root = NULL;
89 std::string error; 88 std::string error;
90 if (!serializer.Deserialize(&root, &error)) { 89 if (!serializer.Deserialize(&root, &error)) {
91 ReportExtensionLoadError(frontend.get(), child_path, error); 90 ReportExtensionLoadError(frontend.get(), child_path.ToWStringHack(),
91 error);
92 continue; 92 continue;
93 } 93 }
94 94
95 scoped_ptr<Value> scoped_root(root); 95 scoped_ptr<Value> scoped_root(root);
96 if (!root->IsType(Value::TYPE_DICTIONARY)) { 96 if (!root->IsType(Value::TYPE_DICTIONARY)) {
97 ReportExtensionLoadError(frontend.get(), child_path, 97 ReportExtensionLoadError(frontend.get(), child_path.ToWStringHack(),
98 Extension::kInvalidManifestError); 98 Extension::kInvalidManifestError);
99 continue; 99 continue;
100 } 100 }
101 101
102 scoped_ptr<Extension> extension(new Extension()); 102 scoped_ptr<Extension> extension(new Extension());
103 if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root), 103 if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root),
104 &error)) { 104 &error)) {
105 ReportExtensionLoadError(frontend.get(), child_path, error); 105 ReportExtensionLoadError(frontend.get(), child_path.ToWStringHack(),
106 error);
106 continue; 107 continue;
107 } 108 }
108 109
109 extensions->push_back(extension.release()); 110 extensions->push_back(extension.release());
110 } 111 }
111 112
112 ReportExtensionsLoaded(frontend.get(), extensions.release()); 113 ReportExtensionsLoaded(frontend.get(), extensions.release());
113 return true; 114 return true;
114 } 115 }
115 116
116 void ExtensionsServiceBackend::ReportExtensionLoadError( 117 void ExtensionsServiceBackend::ReportExtensionLoadError(
117 ExtensionsServiceFrontendInterface *frontend, const std::wstring& path, 118 ExtensionsServiceFrontendInterface *frontend, const std::wstring& path,
118 const std::string &error) { 119 const std::string &error) {
119 std::string message = StringPrintf("Could not load extension from '%s'. %s", 120 std::string message = StringPrintf("Could not load extension from '%s'. %s",
120 WideToASCII(path).c_str(), error.c_str()); 121 WideToASCII(path).c_str(), error.c_str());
121 frontend->GetMessageLoop()->PostTask(FROM_HERE, NewRunnableMethod( 122 frontend->GetMessageLoop()->PostTask(FROM_HERE, NewRunnableMethod(
122 frontend, &ExtensionsServiceFrontendInterface::OnExtensionLoadError, 123 frontend, &ExtensionsServiceFrontendInterface::OnExtensionLoadError,
123 message)); 124 message));
124 } 125 }
125 126
126 void ExtensionsServiceBackend::ReportExtensionsLoaded( 127 void ExtensionsServiceBackend::ReportExtensionsLoaded(
127 ExtensionsServiceFrontendInterface *frontend, ExtensionList* extensions) { 128 ExtensionsServiceFrontendInterface *frontend, ExtensionList* extensions) {
128 frontend->GetMessageLoop()->PostTask(FROM_HERE, NewRunnableMethod( 129 frontend->GetMessageLoop()->PostTask(FROM_HERE, NewRunnableMethod(
129 frontend, 130 frontend,
130 &ExtensionsServiceFrontendInterface::OnExtensionsLoadedFromDirectory, 131 &ExtensionsServiceFrontendInterface::OnExtensionsLoadedFromDirectory,
131 extensions)); 132 extensions));
132 } 133 }
OLDNEW
« no previous file with comments | « base/file_util_win.cc ('k') | chrome/browser/greasemonkey_master.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698