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

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

Issue 13929003: chromeos: Move chrome/browser/chromeos/extensions/file_handler_util.* to a sub-directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/platform_file.h"
13 #include "chrome/common/extensions/extension.h"
14 #include "extensions/common/url_pattern_set.h"
15
16 class Browser;
17 class FileBrowserHandler;
18 class GURL;
19 class Profile;
20
21 namespace extensions {
22 class Extension;
23 } // namespace extensions
24
25 namespace fileapi {
26 class FileSystemURL;
27 }
28
29 namespace file_handler_util {
30
31 // Specifies the task type for a task id that represents some file action, Drive
32 // action, or Web Intent action.
33 extern const char kTaskFile[];
34 extern const char kTaskDrive[];
35 extern const char kTaskApp[];
36
37 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id);
38
39 // Update the default file handler for the given sets of suffixes and MIME
40 // types.
41 void UpdateDefaultTask(Profile* profile,
42 const std::string& task_id,
43 const std::set<std::string>& suffixes,
44 const std::set<std::string>& mime_types);
45
46 // Returns the task ID of the default task for the given |mime_type|/|suffix|
47 // combination. If it finds a MIME type match, then it prefers that over a
48 // suffix match. If it a default can't be found, then it returns the empty
49 // string.
50 std::string GetDefaultTaskIdFromPrefs(Profile* profile,
51 const std::string& mime_type,
52 const std::string& suffix);
53
54 // Gets read-write file access permission flags.
55 int GetReadWritePermissions();
56 // Gets read-only file access permission flags.
57 int GetReadOnlyPermissions();
58
59 // Generates task id for the action specified by the extension. The |task_type|
60 // must be one of kTaskFile, kTaskDrive or kTaskApp.
61 std::string MakeTaskID(const std::string& extension_id,
62 const std::string& task_type,
63 const std::string& action_id);
64
65 // Extracts action, type and extension id bound to the file task. Either
66 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't
67 // interested in those values. Returns false on failure to parse.
68 bool CrackTaskID(const std::string& task_id,
69 std::string* target_extension_id,
70 std::string* task_type,
71 std::string* action_id);
72
73 // This generates a list of default tasks (tasks set as default by the user in
74 // prefs) from the |common_tasks|.
75 void FindDefaultTasks(Profile* profile,
76 const std::vector<base::FilePath>& files_list,
77 const std::set<const FileBrowserHandler*>& common_tasks,
78 std::set<const FileBrowserHandler*>* default_tasks);
79
80 // This generates list of tasks common for all files in |file_list|.
81 bool FindCommonTasks(Profile* profile,
82 const std::vector<GURL>& files_list,
83 std::set<const FileBrowserHandler*>* common_tasks);
84
85 // Finds a task for a file whose URL is |url| and whose path is |path|.
86 // Returns default task if one is defined (The default task is the task that is
87 // assigned to file browser task button by default). If default task is not
88 // found, tries to match the url with one of the builtin tasks.
89 bool GetTaskForURLAndPath(Profile* profile,
90 const GURL& url,
91 const base::FilePath& path,
92 const FileBrowserHandler** handler);
93
94 // Used for returning success or failure from task executions.
95 typedef base::Callback<void(bool)> FileTaskFinishedCallback;
96
97 // Helper class for executing file browser file action.
98 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> {
99 public:
100 // Creates the appropriate FileTaskExecutor for the given |extension_id|.
101 static FileTaskExecutor* Create(Profile* profile,
102 const GURL& source_url,
103 const std::string& file_browser_id,
104 int32 tab_id,
105 const std::string& extension_id,
106 const std::string& task_type,
107 const std::string& action_id);
108
109 // Same as ExecuteAndNotify, but no notification is performed.
110 virtual bool Execute(const std::vector<fileapi::FileSystemURL>& file_urls);
111
112 // Initiates execution of file handler task for each element of |file_urls|.
113 // Return |false| if the execution cannot be initiated. Otherwise returns
114 // |true| and then eventually calls |done| when all the files have
115 // been handled. If there is an error during processing the list of files, the
116 // caller will be informed of the failure via |done|, and the rest of
117 // the files will not be processed.
118 virtual bool ExecuteAndNotify(
119 const std::vector<fileapi::FileSystemURL>& file_urls,
120 const FileTaskFinishedCallback& done) = 0;
121
122 protected:
123 explicit FileTaskExecutor(Profile* profile,
124 const GURL& source_url,
125 const std::string& file_browser_id,
126 const std::string& extension_id);
127 virtual ~FileTaskExecutor();
128
129 // Checks if the file browser extension had file access permissions for the
130 // list of files.
131 bool FileBrowserHasAccessPermissionForFiles(
132 const std::vector<fileapi::FileSystemURL>& files);
133
134 // Returns the profile that this task was created with.
135 Profile* profile() { return profile_; }
136
137 // Returns a browser to use for the current browser.
138 Browser* GetBrowser() const;
139
140 // Returns the extension for this profile.
141 const extensions::Extension* GetExtension();
142
143 // Returns the extension ID set for this FileTaskExecutor.
144 const std::string& extension_id() { return extension_id_; }
145
146 private:
147 friend class base::RefCountedThreadSafe<FileTaskExecutor>;
148
149 Profile* profile_;
150 const GURL source_url_;
151 const std::string file_browser_id_;
152 const std::string extension_id_;
153 };
154
155 } // namespace file_handler_util
156
157 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698