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

Side by Side Diff: chrome/browser/devtools/devtools_file_helper.h

Issue 11570081: Support file system access in DevTools with isolated file system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed methods and added CHECK() Created 7 years, 11 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 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/callback.h" 13 #include "base/callback.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 16
16 class FilePath; 17 class FilePath;
17 class Profile; 18 class Profile;
18 19
20 namespace content {
21 class WebContents;
22 }
23
19 class DevToolsFileHelper { 24 class DevToolsFileHelper {
20 public: 25 public:
21 explicit DevToolsFileHelper(Profile* profile); 26 struct Filesystem {
27 Filesystem();
28 Filesystem(const std::string& filesystem_id,
29 const std::string& registered_name,
30 const std::string& filesystem_path);
31
32 std::string filesystem_id;
33 std::string registered_name;
34 std::string filesystem_path;
35 };
36
37 DevToolsFileHelper(content::WebContents* web_contents, Profile* profile);
22 ~DevToolsFileHelper(); 38 ~DevToolsFileHelper();
23 39
24 typedef base::Callback<void(void)> SaveCallback; 40 typedef base::Callback<void(void)> SaveCallback;
25 typedef base::Callback<void(void)> AppendCallback; 41 typedef base::Callback<void(void)> AppendCallback;
42 typedef base::Callback<
43 void(const std::vector<DevToolsFileHelper::Filesystem>&)>
44 RequestFilesystemsCallback;
45 typedef base::Callback<
46 void(std::string, const DevToolsFileHelper::Filesystem&)>
47 AddFilesystemCallback;
26 48
27 // Saves |content| to the file and associates its path with given |url|. 49 // Saves |content| to the file and associates its path with given |url|.
28 // If client is calling this method with given |url| for the first time 50 // If client is calling this method with given |url| for the first time
29 // or |save_as| is true, confirmation dialog is shown to the user. 51 // or |save_as| is true, confirmation dialog is shown to the user.
30 void Save(const std::string& url, 52 void Save(const std::string& url,
31 const std::string& content, 53 const std::string& content,
32 bool save_as, 54 bool save_as,
33 const SaveCallback& callback); 55 const SaveCallback& callback);
34 56
35 // Append |content| to the file that has been associated with given |url|. 57 // Append |content| to the file that has been associated with given |url|.
36 // The |url| can be associated with a file via calling Save method. 58 // The |url| can be associated with a file via calling Save method.
37 // If the Save method has not been called for this |url|, then 59 // If the Save method has not been called for this |url|, then
38 // Append method does nothing. 60 // Append method does nothing.
39 void Append(const std::string& url, 61 void Append(const std::string& url,
40 const std::string& content, 62 const std::string& content,
41 const AppendCallback& callback); 63 const AppendCallback& callback);
42 64
65 // Shows select folder dialog.
66 // If user cancels folder selection, passes empty Filesystem struct to
67 // |callback|.
68 // If selected folder contains magic file, grants renderer read/write
69 // permissions, registers isolated file system for it and passes Filesystem
70 // struct to |callback|. Saves file system path to prefs.
71 // If selected folder does not contain magic file, passes error string to
72 // |callback|.
73 void AddFilesystem(const AddFilesystemCallback& callback);
74
75 // Loads file system paths from prefs, grants permissions and registers
76 // isolated file system for those of them that contain magic file and passes
77 // Filesystem structs for registered file systems to |callback|.
78 void RequestFilesystems(const RequestFilesystemsCallback& callback);
79
80 // Removes isolated file system for given \filesystem_path|.
kinuko 2013/01/04 14:20:55 nit: \filesystem_path| -> |filesystem_path| ?
vsevik 2013/01/09 11:54:40 Done.
81 void RemoveFilesystem(const std::string& filesystem_path);
82
43 private: 83 private:
44 void SaveAsFileSelected(const std::string& url, 84 void SaveAsFileSelected(const std::string& url,
45 const std::string& content, 85 const std::string& content,
46 const SaveCallback& callback, 86 const SaveCallback& callback,
47 const FilePath& path); 87 const FilePath& path);
48 void SaveAsFileSelectionCanceled(); 88 void SaveAsFileSelectionCanceled();
89 void InnerAddFilesystem(const AddFilesystemCallback& callback,
90 const FilePath& path);
91 void CancelFilesystemAdding(const AddFilesystemCallback& callback);
92 void AddValidatedFilesystem(const AddFilesystemCallback& callback,
93 const std::vector<FilePath>& permitted_paths);
94 void RestoreValidatedFilesystems(const RequestFilesystemsCallback& callback,
95 const std::vector<FilePath>& file_paths);
49 96
97 content::WebContents* web_contents_;
50 Profile* profile_; 98 Profile* profile_;
51 base::WeakPtrFactory<DevToolsFileHelper> weak_factory_; 99 base::WeakPtrFactory<DevToolsFileHelper> weak_factory_;
52 typedef std::map<std::string, FilePath> PathsMap; 100 typedef std::map<std::string, FilePath> PathsMap;
53 PathsMap saved_files_; 101 PathsMap saved_files_;
54 DISALLOW_COPY_AND_ASSIGN(DevToolsFileHelper); 102 DISALLOW_COPY_AND_ASSIGN(DevToolsFileHelper);
55 }; 103 };
56 104
57 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ 105 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698