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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 9692049: Gave native File Browser file handlers higher priority than 3rd party handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/chromeos/extensions/file_handler_util.h" 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return false; 170 return false;
171 *extension_id = result[0]; 171 *extension_id = result[0];
172 *action_id = result[1]; 172 *action_id = result[1];
173 return true; 173 return true;
174 } 174 }
175 175
176 // Given the list of selected files, returns array of context menu tasks 176 // Given the list of selected files, returns array of context menu tasks
177 // that are shared 177 // that are shared
178 bool FindCommonTasks(Profile* profile, 178 bool FindCommonTasks(Profile* profile,
179 const std::vector<GURL>& files_list, 179 const std::vector<GURL>& files_list,
180 const std::string& privileged_extension_id,
180 LastUsedHandlerList* named_action_list) { 181 LastUsedHandlerList* named_action_list) {
181 named_action_list->clear(); 182 named_action_list->clear();
182 ActionSet common_tasks; 183 ActionSet common_tasks;
183 for (std::vector<GURL>::const_iterator it = files_list.begin(); 184 for (std::vector<GURL>::const_iterator it = files_list.begin();
184 it != files_list.end(); ++it) { 185 it != files_list.end(); ++it) {
185 ActionSet file_actions; 186 ActionSet file_actions;
186 if (!GetFileBrowserHandlers(profile, *it, &file_actions)) 187 if (!GetFileBrowserHandlers(profile, *it, &file_actions))
187 return false; 188 return false;
188 // If there is nothing to do for one file, the intersection of tasks for all 189 // If there is nothing to do for one file, the intersection of tasks for all
189 // files will be empty at the end. 190 // files will be empty at the end.
(...skipping 16 matching lines...) Expand all
206 } 207 }
207 } 208 }
208 } 209 }
209 210
210 const DictionaryValue* prefs_tasks = 211 const DictionaryValue* prefs_tasks =
211 profile->GetPrefs()->GetDictionary(prefs::kLastUsedFileBrowserHandlers); 212 profile->GetPrefs()->GetDictionary(prefs::kLastUsedFileBrowserHandlers);
212 for (ActionSet::const_iterator iter = common_tasks.begin(); 213 for (ActionSet::const_iterator iter = common_tasks.begin();
213 iter != common_tasks.end(); ++iter) { 214 iter != common_tasks.end(); ++iter) {
214 // Get timestamp of when this task was used last time. 215 // Get timestamp of when this task was used last time.
215 int last_used_timestamp = 0; 216 int last_used_timestamp = 0;
217
218 if ((*iter)->extension_id() == privileged_extension_id) {
219 // Give a little bump to the action from the 'privileged' extension
220 // (normally the File Browser) so that it becomes the default on a fresh
221 // profile when none of the action has been used yet.
222 last_used_timestamp = 1;
223 }
216 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()), 224 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()),
217 &last_used_timestamp); 225 &last_used_timestamp);
218 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list); 226 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list);
219 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter, 227 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter,
220 matching_patterns)); 228 matching_patterns));
221 } 229 }
222 230
223 SortLastUsedHandlerList(named_action_list); 231 SortLastUsedHandlerList(named_action_list);
224 return true; 232 return true;
225 } 233 }
226 234
227 bool GetDefaultTask( 235 bool GetDefaultTask(Profile* profile,
228 Profile* profile, const GURL& url, const FileBrowserHandler** handler) { 236 const GURL& url,
237 const std::string& privileged_extension_id,
238 const FileBrowserHandler** handler) {
229 std::vector<GURL> file_urls; 239 std::vector<GURL> file_urls;
230 file_urls.push_back(url); 240 file_urls.push_back(url);
231 241
232 LastUsedHandlerList common_tasks; 242 LastUsedHandlerList common_tasks;
233 if (!FindCommonTasks(profile, file_urls, &common_tasks)) 243 if (!FindCommonTasks(
244 profile, file_urls, privileged_extension_id, &common_tasks))
234 return false; 245 return false;
235 246
236 if (common_tasks.size() == 0) 247 if (common_tasks.size() == 0)
237 return false; 248 return false;
238 249
239 *handler = common_tasks[0].handler; 250 *handler = common_tasks[0].handler;
240 return true; 251 return true;
241 } 252 }
242 253
243 class FileTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher { 254 class FileTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 base::JSONWriter::Write(event_args.get(), false, &json_args); 549 base::JSONWriter::Write(event_args.get(), false, &json_args);
539 event_router->DispatchEventToExtension( 550 event_router->DispatchEventToExtension(
540 extension_id_, std::string("fileBrowserHandler.onExecute"), 551 extension_id_, std::string("fileBrowserHandler.onExecute"),
541 json_args, profile_, 552 json_args, profile_,
542 GURL()); 553 GURL());
543 Done(true); 554 Done(true);
544 } 555 }
545 556
546 } // namespace file_handler_util 557 } // namespace file_handler_util
547 558
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698