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