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

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

Issue 10411018: [FileBrowser] Added DefaultAction dialog to choose default action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); 68 ExtensionProcessManager* manager = profile->GetExtensionProcessManager();
69 69
70 SiteInstance* site_instance = manager->GetSiteInstanceForURL(extension_url); 70 SiteInstance* site_instance = manager->GetSiteInstanceForURL(extension_url);
71 if (!site_instance || !site_instance->HasProcess()) 71 if (!site_instance || !site_instance->HasProcess())
72 return -1; 72 return -1;
73 content::RenderProcessHost* process = site_instance->GetProcess(); 73 content::RenderProcessHost* process = site_instance->GetProcess();
74 74
75 return process->GetID(); 75 return process->GetID();
76 } 76 }
77 77
78 // Update file handler usage stats.
79 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id) {
80 if (!profile || !profile->GetPrefs())
81 return;
82 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(),
83 prefs::kLastUsedFileBrowserHandlers);
84 prefs_usage_update->SetWithoutPathExpansion(task_id,
85 new base::FundamentalValue(
86 static_cast<int>(base::Time::Now().ToInternalValue()/
87 base::Time::kMicrosecondsPerSecond)));
88 }
89
90 URLPatternSet GetAllMatchingPatterns(const FileBrowserHandler* handler, 78 URLPatternSet GetAllMatchingPatterns(const FileBrowserHandler* handler,
91 const std::vector<GURL>& files_list) { 79 const std::vector<GURL>& files_list) {
92 URLPatternSet matching_patterns; 80 URLPatternSet matching_patterns;
93 const URLPatternSet& patterns = handler->file_url_patterns(); 81 const URLPatternSet& patterns = handler->file_url_patterns();
94 for (URLPatternSet::const_iterator pattern_it = patterns.begin(); 82 for (URLPatternSet::const_iterator pattern_it = patterns.begin();
95 pattern_it != patterns.end(); ++pattern_it) { 83 pattern_it != patterns.end(); ++pattern_it) {
96 for (std::vector<GURL>::const_iterator file_it = files_list.begin(); 84 for (std::vector<GURL>::const_iterator file_it = files_list.begin();
97 file_it != files_list.end(); ++file_it) { 85 file_it != files_list.end(); ++file_it) {
98 if (pattern_it->MatchesURL(*file_it)) { 86 if (pattern_it->MatchesURL(*file_it)) {
99 matching_patterns.AddPattern(*pattern_it); 87 matching_patterns.AddPattern(*pattern_it);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Sort by the last used descending. 181 // Sort by the last used descending.
194 std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc); 182 std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc);
195 if (list->size() > 1) { 183 if (list->size() > 1) {
196 // Sort the rest by name. 184 // Sort the rest by name.
197 std::sort(list->begin() + 1, list->end(), SortByTaskName); 185 std::sort(list->begin() + 1, list->end(), SortByTaskName);
198 } 186 }
199 } 187 }
200 188
201 } // namespace 189 } // namespace
202 190
191 // Update file handler usage stats.
192 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id) {
193 if (!profile || !profile->GetPrefs())
194 return;
195 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(),
196 prefs::kLastUsedFileBrowserHandlers);
197 prefs_usage_update->SetWithoutPathExpansion(task_id,
198 new base::FundamentalValue(
199 static_cast<int>(base::Time::Now().ToInternalValue()/
200 base::Time::kMicrosecondsPerSecond)));
201 }
202
203 int GetReadWritePermissions() { 203 int GetReadWritePermissions() {
204 return kReadWriteFilePermissions; 204 return kReadWriteFilePermissions;
205 } 205 }
206 206
207 int GetReadOnlyPermissions() { 207 int GetReadOnlyPermissions() {
208 return kReadOnlyFilePermissions; 208 return kReadOnlyFilePermissions;
209 } 209 }
210 210
211 std::string MakeTaskID(const std::string& extension_id, 211 std::string MakeTaskID(const std::string& extension_id,
212 const std::string& action_id) { 212 const std::string& action_id) {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 file_def->SetBoolean("fileIsDirectory", iter->is_directory); 627 file_def->SetBoolean("fileIsDirectory", iter->is_directory);
628 } 628 }
629 // Get tab id. 629 // Get tab id.
630 Browser* current_browser = browser(); 630 Browser* current_browser = browser();
631 if (current_browser) { 631 if (current_browser) {
632 WebContents* contents = current_browser->GetSelectedWebContents(); 632 WebContents* contents = current_browser->GetSelectedWebContents();
633 if (contents) 633 if (contents)
634 details->SetInteger("tab_id", ExtensionTabUtil::GetTabId(contents)); 634 details->SetInteger("tab_id", ExtensionTabUtil::GetTabId(contents));
635 } 635 }
636 636
637 UpdateFileHandlerUsageStats(profile_, MakeTaskID(extension_id_, action_id_));
638
639 std::string json_args; 637 std::string json_args;
640 base::JSONWriter::Write(event_args.get(), &json_args); 638 base::JSONWriter::Write(event_args.get(), &json_args);
641 event_router->DispatchEventToExtension( 639 event_router->DispatchEventToExtension(
642 extension_id_, std::string("fileBrowserHandler.onExecute"), 640 extension_id_, std::string("fileBrowserHandler.onExecute"),
643 json_args, profile_, 641 json_args, profile_,
644 GURL()); 642 GURL());
645 643
646 Done(true); 644 Done(true);
647 } 645 }
648 646
(...skipping 29 matching lines...) Expand all
678 handler_host_permissions_[i].first, 676 handler_host_permissions_[i].first,
679 handler_host_permissions_[i].second); 677 handler_host_permissions_[i].second);
680 } 678 }
681 679
682 // We don't need this anymore. 680 // We don't need this anymore.
683 handler_host_permissions_.clear(); 681 handler_host_permissions_.clear();
684 } 682 }
685 683
686 } // namespace file_handler_util 684 } // namespace file_handler_util
687 685
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698