summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorloislo@chromium.org <loislo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-02 07:48:42 +0000
committerloislo@chromium.org <loislo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-02 07:48:42 +0000
commite2641d881d24be43d5ddaa4ea72a23fb9cf41df0 (patch)
treefd4da7ce734a23b4578f7868447cebc6e5ec5b01
parent86bb87e4fdb5bf9e2188b77dbb2fe19bd7c757fe (diff)
downloadchromium_src-e2641d881d24be43d5ddaa4ea72a23fb9cf41df0.zip
chromium_src-e2641d881d24be43d5ddaa4ea72a23fb9cf41df0.tar.gz
chromium_src-e2641d881d24be43d5ddaa4ea72a23fb9cf41df0.tar.bz2
DevTools: AppendFile implementation.
DevTools wants to save very big files like HeapSnapshots. It is not possible at the moment because the file can be about ~6Gb. BUG=none TEST=FileUtilTest.AppendFile Review URL: https://chromiumcodereview.appspot.com/10240002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134877 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/debugger/devtools_file_helper.cc26
-rw-r--r--chrome/browser/debugger/devtools_file_helper.h14
-rw-r--r--chrome/browser/debugger/devtools_window.cc12
-rw-r--r--chrome/browser/debugger/devtools_window.h6
-rw-r--r--content/browser/debugger/devtools_frontend_host.cc13
-rw-r--r--content/browser/debugger/devtools_frontend_host.h5
-rw-r--r--content/common/devtools_messages.h6
-rw-r--r--content/public/browser/devtools_frontend_host_delegate.h5
-rw-r--r--content/renderer/devtools_client.cc9
-rw-r--r--content/renderer/devtools_client.h4
10 files changed, 84 insertions, 16 deletions
diff --git a/chrome/browser/debugger/devtools_file_helper.cc b/chrome/browser/debugger/devtools_file_helper.cc
index a2234d2..1dd41ab 100644
--- a/chrome/browser/debugger/devtools_file_helper.cc
+++ b/chrome/browser/debugger/devtools_file_helper.cc
@@ -94,6 +94,15 @@ void DevToolsFileHelper::WriteFile(const FilePath& path,
file_util::WriteFile(path, content.c_str(), content.length());
}
+// static
+void DevToolsFileHelper::AppendToFile(const FilePath& path,
+ const std::string& content) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ DCHECK(!path.empty());
+
+ file_util::AppendToFile(path, content.c_str(), content.length());
+}
+
DevToolsFileHelper::DevToolsFileHelper(Profile* profile, Delegate* delegate)
: profile_(profile),
delegate_(delegate) {
@@ -145,6 +154,21 @@ void DevToolsFileHelper::Save(const std::string& url,
save_as_dialog_->Show(url, initial_path, content);
}
+void DevToolsFileHelper::Append(const std::string& url,
+ const std::string& content) {
+ PathsMap::iterator it = saved_files_.find(url);
+ if (it == saved_files_.end())
+ return;
+
+ delegate_->AppendedTo(url);
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DevToolsFileHelper::AppendToFile,
+ it->second,
+ content));
+}
+
void DevToolsFileHelper::FileSelected(const std::string& url,
const FilePath& path,
const std::string& content) {
@@ -156,7 +180,7 @@ void DevToolsFileHelper::FileSelected(const std::string& url,
DictionaryValue* files_map = update.Get();
files_map->SetWithoutPathExpansion(base::MD5String(url),
base::CreateFilePathValue(path));
- delegate_->FileSavedAs(url, path);
+ delegate_->FileSavedAs(url);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
diff --git a/chrome/browser/debugger/devtools_file_helper.h b/chrome/browser/debugger/devtools_file_helper.h
index 539e137..91062b1 100644
--- a/chrome/browser/debugger/devtools_file_helper.h
+++ b/chrome/browser/debugger/devtools_file_helper.h
@@ -17,12 +17,11 @@ class Profile;
class DevToolsFileHelper {
public:
- static void WriteFile(const FilePath& path, const std::string& content);
-
class Delegate {
public:
virtual ~Delegate() {}
- virtual void FileSavedAs(const std::string& url, const FilePath& path) = 0;
+ virtual void FileSavedAs(const std::string& url) = 0;
+ virtual void AppendedTo(const std::string& url) = 0;
};
DevToolsFileHelper(Profile* profile, Delegate* delegate);
@@ -35,11 +34,20 @@ class DevToolsFileHelper {
const std::string& content,
bool save_as);
+ // 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);
private:
+ static void WriteFile(const FilePath& path, const std::string& content);
+ static void AppendToFile(const FilePath& path, const std::string& content);
+
class SaveAsDialog;
Profile* profile_;
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc
index c69a635..81c6129 100644
--- a/chrome/browser/debugger/devtools_window.cc
+++ b/chrome/browser/debugger/devtools_window.cc
@@ -739,11 +739,21 @@ void DevToolsWindow::SaveToFile(const std::string& url,
file_helper_->Save(url, content, save_as);
}
-void DevToolsWindow::FileSavedAs(const std::string& url, const FilePath& path) {
+void DevToolsWindow::AppendToFile(const std::string& url,
+ const std::string& content) {
+ file_helper_->Append(url, content);
+}
+
+void DevToolsWindow::FileSavedAs(const std::string& url) {
StringValue url_value(url);
CallClientFunction("InspectorFrontendAPI.savedURL", &url_value);
}
+void DevToolsWindow::AppendedTo(const std::string& url) {
+ StringValue url_value(url);
+ CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value);
+}
+
content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() {
if (inspected_tab_ && inspected_tab_->web_contents()->GetDelegate()) {
return inspected_tab_->web_contents()->GetDelegate()->
diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h
index 6d5f1bc..b7ae297 100644
--- a/chrome/browser/debugger/devtools_window.h
+++ b/chrome/browser/debugger/devtools_window.h
@@ -142,10 +142,12 @@ class DevToolsWindow : private content::NotificationObserver,
virtual void SaveToFile(const std::string& url,
const std::string& content,
bool save_as) OVERRIDE;
+ virtual void AppendToFile(const std::string& url,
+ const std::string& content) OVERRIDE;
// Overridden from DevToolsFileHelper::Delegate
- virtual void FileSavedAs(const std::string& url,
- const FilePath& path) OVERRIDE;
+ virtual void FileSavedAs(const std::string& url) OVERRIDE;
+ virtual void AppendedTo(const std::string& url) OVERRIDE;
void RequestSetDocked(bool docked);
diff --git a/content/browser/debugger/devtools_frontend_host.cc b/content/browser/debugger/devtools_frontend_host.cc
index fcf0e74..54beb1a 100644
--- a/content/browser/debugger/devtools_frontend_host.cc
+++ b/content/browser/debugger/devtools_frontend_host.cc
@@ -74,10 +74,9 @@ bool DevToolsFrontendHost::OnMessageReceived(
OnRequestUndockWindow)
IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestSetDockSide,
OnRequestSetDockSide)
- IPC_MESSAGE_HANDLER(DevToolsHostMsg_OpenInNewTab,
- OnOpenInNewTab)
- IPC_MESSAGE_HANDLER(DevToolsHostMsg_Save,
- OnSave)
+ IPC_MESSAGE_HANDLER(DevToolsHostMsg_OpenInNewTab, OnOpenInNewTab)
+ IPC_MESSAGE_HANDLER(DevToolsHostMsg_Save, OnSave)
+ IPC_MESSAGE_HANDLER(DevToolsHostMsg_Append, OnAppend)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -112,6 +111,12 @@ void DevToolsFrontendHost::OnSave(
delegate_->SaveToFile(url, content, save_as);
}
+void DevToolsFrontendHost::OnAppend(
+ const std::string& url,
+ const std::string& content) {
+ delegate_->AppendToFile(url, content);
+}
+
void DevToolsFrontendHost::OnRequestDockWindow() {
delegate_->DockWindow();
}
diff --git a/content/browser/debugger/devtools_frontend_host.h b/content/browser/debugger/devtools_frontend_host.h
index 0845e23..6590a95 100644
--- a/content/browser/debugger/devtools_frontend_host.h
+++ b/content/browser/debugger/devtools_frontend_host.h
@@ -48,9 +48,8 @@ class DevToolsFrontendHost : public DevToolsClientHost,
void OnRequestUndockWindow();
void OnRequestSetDockSide(const std::string& side);
void OnOpenInNewTab(const std::string& url);
- void OnSave(const std::string& url,
- const std::string& content,
- bool save_as);
+ void OnSave(const std::string& url, const std::string& content, bool save_as);
+ void OnAppend(const std::string& url, const std::string& content);
WebContentsImpl* web_contents_;
DevToolsFrontendHostDelegate* delegate_;
diff --git a/content/common/devtools_messages.h b/content/common/devtools_messages.h
index 99f08ac..4f2d078 100644
--- a/content/common/devtools_messages.h
+++ b/content/common/devtools_messages.h
@@ -155,6 +155,12 @@ IPC_MESSAGE_ROUTED3(DevToolsHostMsg_Save,
std::string /* content */,
bool /* save_as */)
+// Appends given |content| to the file that has been associated with the
+// given |url| by Save message handler.
+IPC_MESSAGE_ROUTED2(DevToolsHostMsg_Append,
+ std::string /* url */,
+ std::string /* content */)
+
// Updates agent runtime state stored in devtools manager in order to support
// cross-navigation instrumentation.
IPC_MESSAGE_ROUTED1(DevToolsHostMsg_SaveAgentRuntimeState,
diff --git a/content/public/browser/devtools_frontend_host_delegate.h b/content/public/browser/devtools_frontend_host_delegate.h
index 50a95df..66bc3e1 100644
--- a/content/public/browser/devtools_frontend_host_delegate.h
+++ b/content/public/browser/devtools_frontend_host_delegate.h
@@ -45,6 +45,11 @@ class DevToolsFrontendHostDelegate {
const std::string& content,
bool save_as) = 0;
+ // Appends given |content| to the file that has been associated with the
+ // given |url| by SaveToFile method.
+ virtual void AppendToFile(const std::string& url,
+ const std::string& content) = 0;
+
// This method is called when the contents inspected by this devtools frontend
// is closing.
virtual void InspectedContentsClosing() = 0;
diff --git a/content/renderer/devtools_client.cc b/content/renderer/devtools_client.cc
index 0bc3523..ae293e3 100644
--- a/content/renderer/devtools_client.cc
+++ b/content/renderer/devtools_client.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -88,6 +88,13 @@ void DevToolsClient::save(const WebKit::WebString& url,
save_as));
}
+void DevToolsClient::append(const WebKit::WebString& url,
+ const WebKit::WebString& content) {
+ Send(new DevToolsHostMsg_Append(routing_id(),
+ url.utf8(),
+ content.utf8()));
+}
+
void DevToolsClient::OnDispatchOnInspectorFrontend(const std::string& message) {
web_tools_frontend_->dispatchOnInspectorFrontend(
WebString::fromUTF8(message));
diff --git a/content/renderer/devtools_client.h b/content/renderer/devtools_client.h
index 6d7e05d..e1527f6 100644
--- a/content/renderer/devtools_client.h
+++ b/content/renderer/devtools_client.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -49,6 +49,8 @@ class DevToolsClient : public content::RenderViewObserver,
virtual void save(const WebKit::WebString& url,
const WebKit::WebString& content,
bool save_as) OVERRIDE;
+ virtual void append(const WebKit::WebString& url,
+ const WebKit::WebString& content) OVERRIDE;
void OnDispatchOnInspectorFrontend(const std::string& message);