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

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

Issue 10834383: Chrome OS "open with" picker allowing Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: reorder class, revert net/* Created 8 years, 3 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
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 #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 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/file_browser_handler.h" 13 #include "chrome/common/extensions/file_browser_handler.h"
14 #include "chrome/common/extensions/url_pattern_set.h" 14 #include "chrome/common/extensions/url_pattern_set.h"
15 15
16 class Browser; 16 class Browser;
17 class GURL; 17 class GURL;
18 class Profile; 18 class Profile;
19 19
20 namespace extensions {
21 class Extension;
22 } // namespace extensions
23
20 namespace file_handler_util { 24 namespace file_handler_util {
21 25
26 // Specifies the task type for a task id that represents some file action, Drive
27 // action, or Web Intent action.
28 enum TaskType {
29 TASK_FILE = 1,
30 TASK_DRIVE,
31 TASK_WEBINTENT
32 };
33
34 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id);
35
22 // Update the default file handler for the given sets of suffixes and MIME 36 // Update the default file handler for the given sets of suffixes and MIME
23 // types. 37 // types.
24 void UpdateDefaultTask(Profile* profile, 38 void UpdateDefaultTask(Profile* profile,
25 const std::string& task_id, 39 const std::string& task_id,
26 const std::set<std::string>& suffixes, 40 const std::set<std::string>& suffixes,
27 const std::set<std::string>& mime_types); 41 const std::set<std::string>& mime_types);
28 42
29 // Returns the task ID of the default task for the given |mime_type|/|suffix| 43 // Returns the task ID of the default task for the given |mime_type|/|suffix|
30 // combination. If it finds a MIME type match, then it prefers that over a 44 // combination. If it finds a MIME type match, then it prefers that over a
31 // suffix match. If it a default can't be found, then it returns the empty 45 // suffix match. If it a default can't be found, then it returns the empty
32 // string. 46 // string.
33 std::string GetDefaultTaskIdFromPrefs(Profile* profile, 47 std::string GetDefaultTaskIdFromPrefs(Profile* profile,
34 const std::string& mime_type, 48 const std::string& mime_type,
35 const std::string& suffix); 49 const std::string& suffix);
36 50
37 // Gets read-write file access permission flags. 51 // Gets read-write file access permission flags.
38 int GetReadWritePermissions(); 52 int GetReadWritePermissions();
39 // Gets read-only file access permission flags. 53 // Gets read-only file access permission flags.
40 int GetReadOnlyPermissions(); 54 int GetReadOnlyPermissions();
41 55
42 // Generates file task id for the file action specified by the extension. 56 // Generates task id for the action specified by the extension.
43 std::string MakeTaskID(const std::string& extension_id, 57 std::string MakeTaskID(const std::string& extension_id,
58 TaskType task_type,
44 const std::string& action_id); 59 const std::string& action_id);
45 60
46 // Make a task id specific to drive apps instead of extensions. 61 // Extracts action, type and extension id bound to the file task. Either
47 std::string MakeDriveTaskID(const std::string& app_id,
48 const std::string& action_id);
49
50 // Returns the |target_id| and |action_id| of a drive app or extension, given
51 // the drive |task_id| created by MakeDriveTaskID. If the |task_id| is a drive
52 // task_id then it will return true. If not, or if parsing fails, will return
53 // false and not set |app_id| or |action_id|.
54 bool CrackDriveTaskID(const std::string& task_id,
55 std::string* app_id,
56 std::string* action_id);
57
58 // Extracts action and extension id bound to the file task. Either
59 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't 62 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't
60 // interested in those values. Returns false on failure to parse. 63 // interested in those values. Returns false on failure to parse.
61 bool CrackTaskID(const std::string& task_id, 64 bool CrackTaskID(const std::string& task_id,
62 std::string* target_extension_id, 65 std::string* target_extension_id,
66 TaskType* task_type,
63 std::string* action_id); 67 std::string* action_id);
64 68
65 // This generates a list of default tasks (tasks set as default by the user in 69 // This generates a list of default tasks (tasks set as default by the user in
66 // prefs) from the |common_tasks|. 70 // prefs) from the |common_tasks|.
67 void FindDefaultTasks(Profile* profile, 71 void FindDefaultTasks(Profile* profile,
68 const std::vector<GURL>& files_list, 72 const std::vector<GURL>& files_list,
69 const std::set<const FileBrowserHandler*>& common_tasks, 73 const std::set<const FileBrowserHandler*>& common_tasks,
70 std::set<const FileBrowserHandler*>* default_tasks); 74 std::set<const FileBrowserHandler*>* default_tasks);
71 75
72 // This generates list of tasks common for all files in |file_list|. 76 // This generates list of tasks common for all files in |file_list|.
73 bool FindCommonTasks(Profile* profile, 77 bool FindCommonTasks(Profile* profile,
74 const std::vector<GURL>& files_list, 78 const std::vector<GURL>& files_list,
75 std::set<const FileBrowserHandler*>* common_tasks); 79 std::set<const FileBrowserHandler*>* common_tasks);
76 80
77 // Find the default task for a file whose url is |url|. (The default task is the 81 // Find the default task for a file whose url is |url|. (The default task is the
78 // task that is assigned to file browser task button by default). 82 // task that is assigned to file browser task button by default).
79 bool GetDefaultTask(Profile* profile, 83 bool GetDefaultTask(Profile* profile,
80 const GURL& url, 84 const GURL& url,
81 const FileBrowserHandler** handler); 85 const FileBrowserHandler** handler);
82 86
83 // Used for returning success or failure from task executions. 87 // Used for returning success or failure from task executions.
84 typedef base::Callback<void(bool)> FileTaskFinishedCallback; 88 typedef base::Callback<void(bool)> FileTaskFinishedCallback;
85 89
86 // Helper class for executing file browser file action. 90 // Helper class for executing file browser file action.
87 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { 91 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> {
88 public: 92 public:
89 static const char kDriveTaskExtensionPrefix[];
90 static const size_t kDriveTaskExtensionPrefixLength;
91
92 // Creates the appropriate FileTaskExecutor for the given |extension_id|. 93 // Creates the appropriate FileTaskExecutor for the given |extension_id|.
93 static FileTaskExecutor* Create(Profile* profile, 94 static FileTaskExecutor* Create(Profile* profile,
94 const GURL source_url, 95 const GURL source_url,
95 const std::string& extension_id, 96 const std::string& extension_id,
97 TaskType task_type,
96 const std::string& action_id); 98 const std::string& action_id);
97 99
98 // Same as ExecuteAndNotify, but no notification is performed. 100 // Same as ExecuteAndNotify, but no notification is performed.
99 virtual bool Execute(const std::vector<GURL>& file_urls); 101 virtual bool Execute(const std::vector<GURL>& file_urls);
100 102
101 // Initiates execution of file handler task for each element of |file_urls|. 103 // Initiates execution of file handler task for each element of |file_urls|.
102 // Return |false| if the execution cannot be initiated. Otherwise returns 104 // Return |false| if the execution cannot be initiated. Otherwise returns
103 // |true| and then eventually calls |done| when all the files have 105 // |true| and then eventually calls |done| when all the files have
104 // been handled. If there is an error during processing the list of files, the 106 // been handled. If there is an error during processing the list of files, the
105 // caller will be informed of the failure via |done|, and the rest of 107 // caller will be informed of the failure via |done|, and the rest of
106 // the files will not be processed. 108 // the files will not be processed.
107 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, 109 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls,
108 const FileTaskFinishedCallback& done) = 0; 110 const FileTaskFinishedCallback& done) = 0;
109 111
110 protected: 112 protected:
111 explicit FileTaskExecutor(Profile* profile); 113 explicit FileTaskExecutor(Profile* profile, const std::string& extension_id);
112 virtual ~FileTaskExecutor(); 114 virtual ~FileTaskExecutor();
113 115
114 // Returns the profile that this task was created with. 116 // Returns the profile that this task was created with.
115 Profile* profile() { return profile_; } 117 Profile* profile() { return profile_; }
116 118
117 // Returns a browser to use for the current browser. 119 // Returns a browser to use for the current browser.
118 Browser* GetBrowser() const; 120 Browser* GetBrowser() const;
121
122 // Returns the extension for this profile.
123 const extensions::Extension* GetExtension();
124
125 // Returns the extension ID set for this FileTaskExecutor.
126 const std::string& extension_id() { return extension_id_; }
127
119 private: 128 private:
120 friend class base::RefCountedThreadSafe<FileTaskExecutor>; 129 friend class base::RefCountedThreadSafe<FileTaskExecutor>;
121 130
122 Profile* profile_; 131 Profile* profile_;
132 const std::string extension_id_;
123 }; 133 };
124 134
125 } // namespace file_handler_util 135 } // namespace file_handler_util
126 136
127 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ 137 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698