| 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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "chrome/common/extensions/url_pattern_set.h" | 11 #include "chrome/common/extensions/url_pattern_set.h" |
| 12 | 12 |
| 13 class Browser; | 13 class Browser; |
| 14 class FileBrowserHandler; | 14 class FileBrowserHandler; |
| 15 class GURL; | 15 class GURL; |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace file_handler_util { | 18 namespace file_handler_util { |
| 19 | 19 |
| 20 // Gets read-write file access permission flags. |
| 20 int GetReadWritePermissions(); | 21 int GetReadWritePermissions(); |
| 22 // Gets read-only file access permission flags. |
| 23 int GetReadOnlyPermissions(); |
| 21 | 24 |
| 25 // Generates file task id for the file actin specified by the extension. |
| 22 std::string MakeTaskID(const std::string& extension_id, | 26 std::string MakeTaskID(const std::string& extension_id, |
| 23 const std::string& action_id); | 27 const std::string& action_id); |
| 24 | 28 |
| 29 // Extracts action and extension id bound to the file task. |
| 25 bool CrackTaskID(const std::string& task_id, | 30 bool CrackTaskID(const std::string& task_id, |
| 26 std::string* target_extension_id, | 31 std::string* target_extension_id, |
| 27 std::string* action_id); | 32 std::string* action_id); |
| 28 | 33 |
| 34 // Struct that keeps track of when a handler was `last used. |
| 35 // It is used to determine default file action for a file. |
| 29 struct LastUsedHandler { | 36 struct LastUsedHandler { |
| 30 LastUsedHandler(int t, const FileBrowserHandler* h, URLPatternSet p) | 37 LastUsedHandler(int t, const FileBrowserHandler* h, URLPatternSet p) |
| 31 : timestamp(t), | 38 : timestamp(t), |
| 32 handler(h), | 39 handler(h), |
| 33 patterns(p) { | 40 patterns(p) { |
| 34 } | 41 } |
| 35 | 42 |
| 36 int timestamp; | 43 int timestamp; |
| 37 const FileBrowserHandler* handler; | 44 const FileBrowserHandler* handler; |
| 38 URLPatternSet patterns; | 45 URLPatternSet patterns; |
| 39 }; | 46 }; |
| 40 | 47 |
| 41 typedef std::vector<LastUsedHandler> LastUsedHandlerList; | 48 typedef std::vector<LastUsedHandler> LastUsedHandlerList; |
| 42 | 49 |
| 50 // Generates list of tasks common for all files in |file_list|. |
| 51 // The resulting list is sorted by last usage time. |
| 43 bool FindCommonTasks(Profile* profile, | 52 bool FindCommonTasks(Profile* profile, |
| 44 const std::vector<GURL>& files_list, | 53 const std::vector<GURL>& files_list, |
| 45 LastUsedHandlerList* named_action_list); | 54 LastUsedHandlerList* named_action_list); |
| 46 | 55 |
| 56 // Find the default task for a file whose url is |url|. (The default task is the |
| 57 // task that is assigned to file browser task button by default). |
| 47 bool GetDefaultTask(Profile* profile, | 58 bool GetDefaultTask(Profile* profile, |
| 48 const GURL& url, | 59 const GURL& url, |
| 49 const FileBrowserHandler** handler); | 60 const FileBrowserHandler** handler); |
| 50 | 61 |
| 62 // Helper class for executing file browser file action. |
| 51 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { | 63 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { |
| 52 public: | 64 public: |
| 53 | 65 |
| 54 FileTaskExecutor(Profile* profile, | 66 FileTaskExecutor(Profile* profile, |
| 55 const GURL source_url, | 67 const GURL source_url, |
| 56 const std::string& extension_id, | 68 const std::string& extension_id, |
| 57 const std::string& action_id); | 69 const std::string& action_id); |
| 58 | 70 |
| 59 virtual ~FileTaskExecutor(); | 71 virtual ~FileTaskExecutor(); |
| 60 | 72 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 88 | 100 |
| 89 Profile* profile_; | 101 Profile* profile_; |
| 90 const GURL source_url_; | 102 const GURL source_url_; |
| 91 const std::string extension_id_; | 103 const std::string extension_id_; |
| 92 const std::string action_id_; | 104 const std::string action_id_; |
| 93 }; | 105 }; |
| 94 | 106 |
| 95 } // namespace file_handler_util | 107 } // namespace file_handler_util |
| 96 | 108 |
| 97 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 109 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
| OLD | NEW |