summaryrefslogtreecommitdiffstats
path: root/chrome/browser/devtools/devtools_file_helper.h
diff options
context:
space:
mode:
authorvsevik@chromium.org <vsevik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-27 15:35:36 +0000
committervsevik@chromium.org <vsevik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-27 15:35:36 +0000
commitd879ed35085283ccbfdf2ab62b112f6562378db4 (patch)
tree654c798c1433d85eadb21fe0f8ae8dc96a63405f /chrome/browser/devtools/devtools_file_helper.h
parentff0df6be09a5512cffa51777a3132ca469293ad0 (diff)
downloadchromium_src-d879ed35085283ccbfdf2ab62b112f6562378db4.zip
chromium_src-d879ed35085283ccbfdf2ab62b112f6562378db4.tar.gz
chromium_src-d879ed35085283ccbfdf2ab62b112f6562378db4.tar.bz2
Refactor DevtoolsFileHelper: make select file dialog reusable and use callbacks instead of delegate.
BUG=167511 Review URL: https://chromiumcodereview.appspot.com/11684004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174683 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/devtools/devtools_file_helper.h')
-rw-r--r--chrome/browser/devtools/devtools_file_helper.h37
1 files changed, 17 insertions, 20 deletions
diff --git a/chrome/browser/devtools/devtools_file_helper.h b/chrome/browser/devtools/devtools_file_helper.h
index 3c1e9dc..b894a73 100644
--- a/chrome/browser/devtools/devtools_file_helper.h
+++ b/chrome/browser/devtools/devtools_file_helper.h
@@ -9,49 +9,46 @@
#include <string>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
class FilePath;
class Profile;
class DevToolsFileHelper {
public:
- class Delegate {
- public:
- virtual ~Delegate() {}
- virtual void FileSavedAs(const std::string& url) = 0;
- virtual void AppendedTo(const std::string& url) = 0;
- };
-
- DevToolsFileHelper(Profile* profile, Delegate* delegate);
+ explicit DevToolsFileHelper(Profile* profile);
~DevToolsFileHelper();
+ typedef base::Callback<void(void)> SaveCallback;
+ typedef base::Callback<void(void)> AppendCallback;
+
// Saves |content| to the file and associates its path with given |url|.
// If client is calling this method with given |url| for the first time
// or |save_as| is true, confirmation dialog is shown to the user.
void Save(const std::string& url,
const std::string& content,
- bool save_as);
+ bool save_as,
+ const SaveCallback& callback);
// Append |content| to the file that has been associated with given |url|.
// The |url| can be associated with a file via calling Save method.
// If the Save method has not been called for this |url|, then
// Append method does nothing.
- void Append(const std::string& url, const std::string& content);
-
- void FileSelected(const std::string& url,
- const FilePath& path,
- const std::string& content);
+ void Append(const std::string& url,
+ const std::string& content,
+ const AppendCallback& callback);
private:
- static void WriteFile(const FilePath& path, const std::string& content);
- static void AppendToFile(const FilePath& path, const std::string& content);
-
- class SaveAsDialog;
+ void SaveAsFileSelected(const std::string& url,
+ const std::string& content,
+ const SaveCallback& callback,
+ const FilePath& path);
+ void SaveAsFileSelectionCanceled();
Profile* profile_;
- Delegate* delegate_;
- scoped_refptr<SaveAsDialog> save_as_dialog_;
+ base::WeakPtrFactory<DevToolsFileHelper> weak_factory_;
typedef std::map<std::string, FilePath> PathsMap;
PathsMap saved_files_;
DISALLOW_COPY_AND_ASSIGN(DevToolsFileHelper);