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

Unified Diff: chrome/browser/chromeos/gdata/gdata.cc

Issue 9662041: Implement copy and move operations within the same remote file system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/gdata/gdata.cc
===================================================================
--- chrome/browser/chromeos/gdata/gdata.cc (revision 126063)
+++ chrome/browser/chromeos/gdata/gdata.cc (working copy)
@@ -35,6 +35,7 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
+#include "net/base/escape.h"
#include "net/base/file_stream.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
@@ -334,9 +335,12 @@
// Overridden from GDataOperationInterface.
virtual void Start(const std::string& auth_token) OVERRIDE {
DCHECK(!auth_token.empty());
+
GURL url = GetURL();
- url_fetcher_.reset(URLFetcher::Create(
- url, GetRequestType(), this));
+ DCHECK(!url.is_empty());
+ DVLOG(1) << "URL: " << url.spec();
+
+ url_fetcher_.reset(URLFetcher::Create(url, GetRequestType(), this));
url_fetcher_->SetRequestContext(profile_->GetRequestContext());
// Always set flags to neither send nor save cookies.
url_fetcher_->SetLoadFlags(
@@ -356,7 +360,7 @@
std::vector<std::string> headers = GetExtraRequestHeaders();
for (size_t i = 0; i < headers.size(); ++i) {
url_fetcher_->AddExtraRequestHeader(headers[i]);
- DVLOG(1) << "Extra header " << headers[i];
+ DVLOG(1) << "Extra header: " << headers[i];
}
// Set upload data if available.
@@ -784,6 +788,258 @@
return true;
}
+//=========================== CopyDocumentOperation ============================
+
+// Operation for making a copy of a document.
+class CopyDocumentOperation : public GetDataOperation {
+ public:
+ CopyDocumentOperation(GDataOperationRegistry* registry,
+ Profile* profile,
+ const GetDataCallback& callback,
+ const GURL& document_url,
+ const FilePath::StringType& new_name);
satorux1 2012/03/12 17:48:24 just fyi: matter of taste, but for small classes l
Ben Chan 2012/03/13 00:29:21 I had a discussion with Zel that we would like to
+ virtual ~CopyDocumentOperation() {}
+
+ private:
+ // Overridden from GetDataOperation.
+ virtual URLFetcher::RequestType GetRequestType() const OVERRIDE;
+
+ // Overridden from UrlFetchOperation.
+ virtual GURL GetURL() const OVERRIDE;
+ virtual bool GetContentData(std::string* upload_content_type,
+ std::string* upload_content) OVERRIDE;
+
+ GURL document_url_;
+ FilePath::StringType new_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(CopyDocumentOperation);
+};
+
+CopyDocumentOperation::CopyDocumentOperation(
+ GDataOperationRegistry* registry,
+ Profile* profile,
+ const GetDataCallback& callback,
+ const GURL& document_url,
+ const FilePath::StringType& new_name)
+ : GetDataOperation(registry, profile, callback),
+ document_url_(document_url),
+ new_name_(new_name) {
+}
+
+URLFetcher::RequestType CopyDocumentOperation::GetRequestType() const {
+ return URLFetcher::POST;
+}
+
+GURL CopyDocumentOperation::GetURL() const {
+ return AddStandardUrlParams(GURL(kDocumentListRootURL));
+}
+
+bool CopyDocumentOperation::GetContentData(std::string* upload_content_type,
+ std::string* upload_content) {
+ upload_content_type->assign("application/atom+xml");
+ XmlWriter xml_writer;
+ xml_writer.StartWriting();
+ xml_writer.StartElement("entry");
+ xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom");
+
+ xml_writer.WriteElement("id", document_url_.spec());
+ xml_writer.WriteElement("title", new_name_);
+
+ xml_writer.EndElement(); // Ends "entry" element.
+ xml_writer.StopWriting();
+ upload_content->assign(xml_writer.GetWrittenString());
+ DVLOG(1) << "CopyDocumentOperation data: " << *upload_content_type << ", ["
+ << *upload_content << "]";
+ return true;
+}
+
+//=========================== RenameResourceOperation ==========================
+
+class RenameResourceOperation : public EntryActionOperation {
+ public:
+ RenameResourceOperation(GDataOperationRegistry* registry,
+ Profile* profile,
+ const EntryActionCallback& callback,
+ const GURL& document_url,
+ const FilePath::StringType& new_name);
+ virtual ~RenameResourceOperation() {}
+
+ private:
+ // Overridden from EntryActionOperation.
+ virtual URLFetcher::RequestType GetRequestType() const OVERRIDE;
+ virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
+
+ // Overridden from UrlFetchOperation.
+ virtual bool GetContentData(std::string* upload_content_type,
+ std::string* upload_content) OVERRIDE;
+
+ FilePath::StringType new_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(RenameResourceOperation);
+};
+
+RenameResourceOperation::RenameResourceOperation(
+ GDataOperationRegistry* registry,
+ Profile* profile,
+ const EntryActionCallback& callback,
+ const GURL& document_url,
+ const FilePath::StringType& new_name)
+ : EntryActionOperation(registry, profile, callback, document_url),
+ new_name_(new_name) {
+}
+
+URLFetcher::RequestType RenameResourceOperation::GetRequestType() const {
+ return URLFetcher::PUT;
+}
+
+std::vector<std::string>
+RenameResourceOperation::GetExtraRequestHeaders() const {
+ std::vector<std::string> headers;
+ headers.push_back(kIfMatchAllHeader);
+ return headers;
+}
+
+bool RenameResourceOperation::GetContentData(std::string* upload_content_type,
+ std::string* upload_content) {
+ upload_content_type->assign("application/atom+xml");
+ XmlWriter xml_writer;
+ xml_writer.StartWriting();
+ xml_writer.StartElement("entry");
+ xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom");
+
+ xml_writer.WriteElement("title", new_name_);
+
+ xml_writer.EndElement(); // Ends "entry" element.
+ xml_writer.StopWriting();
+ upload_content->assign(xml_writer.GetWrittenString());
+ DVLOG(1) << "RenameResourceOperation data: " << *upload_content_type << ", ["
+ << *upload_content << "]";
+ return true;
+}
+
+//=========================== AddResourceToDirectoryOperation ==================
+
+class AddResourceToDirectoryOperation : public EntryActionOperation {
+ public:
+ AddResourceToDirectoryOperation(GDataOperationRegistry* registry,
+ Profile* profile,
+ const EntryActionCallback& callback,
+ const GURL& parent_content_url,
+ const GURL& document_url);
+ virtual ~AddResourceToDirectoryOperation() {}
+
+ private:
+ // Overridden from EntryActionOperation.
+ virtual GURL GetURL() const OVERRIDE;
+
+ // Overridden from UrlFetchOperation.
+ virtual URLFetcher::RequestType GetRequestType() const OVERRIDE;
+ virtual bool GetContentData(std::string* upload_content_type,
+ std::string* upload_content) OVERRIDE;
+
+ const GURL parent_content_url_;
+
+ DISALLOW_COPY_AND_ASSIGN(AddResourceToDirectoryOperation);
+};
+
+AddResourceToDirectoryOperation::AddResourceToDirectoryOperation(
+ GDataOperationRegistry* registry,
+ Profile* profile,
+ const EntryActionCallback& callback,
+ const GURL& parent_content_url,
+ const GURL& document_url)
+ : EntryActionOperation(registry, profile, callback, document_url),
+ parent_content_url_(parent_content_url) {
+}
+
+GURL AddResourceToDirectoryOperation::GetURL() const {
+ if (!parent_content_url_.is_empty())
+ return AddStandardUrlParams(parent_content_url_);
+
+ return AddStandardUrlParams(GURL(kDocumentListRootURL));
+}
+
+URLFetcher::RequestType
+AddResourceToDirectoryOperation::GetRequestType() const {
+ return URLFetcher::POST;
+}
+
+bool AddResourceToDirectoryOperation::GetContentData(
+ std::string* upload_content_type, std::string* upload_content) {
+ upload_content_type->assign("application/atom+xml");
+ XmlWriter xml_writer;
+ xml_writer.StartWriting();
+ xml_writer.StartElement("entry");
+ xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom");
+
+ xml_writer.WriteElement("id", document_url_.spec());
+
+ xml_writer.EndElement(); // Ends "entry" element.
+ xml_writer.StopWriting();
+ upload_content->assign(xml_writer.GetWrittenString());
+ DVLOG(1) << "AddResourceToDirectoryOperation data: " << *upload_content_type
+ << ", [" << *upload_content << "]";
+ return true;
+}
+
+//=========================== RemoveResourceFromDirectoryOperation =============
+
+class RemoveResourceFromDirectoryOperation : public EntryActionOperation {
+ public:
+ RemoveResourceFromDirectoryOperation(GDataOperationRegistry* registry,
+ Profile* profile,
+ const EntryActionCallback& callback,
+ const GURL& parent_content_url,
+ const GURL& document_url,
+ const std::string& resource_id);
+ virtual ~RemoveResourceFromDirectoryOperation() {}
+
+ private:
+ // Overridden from EntryActionOperation.
+ virtual GURL GetURL() const OVERRIDE;
+
+ // Overridden from UrlFetchOperation.
+ virtual URLFetcher::RequestType GetRequestType() const OVERRIDE;
+ virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
+
+ const std::string resource_id_;
+ const GURL parent_content_url_;
+
+ DISALLOW_COPY_AND_ASSIGN(RemoveResourceFromDirectoryOperation);
+};
+
+RemoveResourceFromDirectoryOperation::RemoveResourceFromDirectoryOperation(
+ GDataOperationRegistry* registry,
+ Profile* profile,
+ const EntryActionCallback& callback,
+ const GURL& parent_content_url,
+ const GURL& document_url,
+ const std::string& document_resource_id)
+ : EntryActionOperation(registry, profile, callback, document_url),
+ resource_id_(document_resource_id),
+ parent_content_url_(parent_content_url) {
+}
+
+GURL RemoveResourceFromDirectoryOperation::GetURL() const {
+ std::string escaped_resource_id = net::EscapePath(resource_id_);
+ GURL edit_url(base::StringPrintf("%s/%s",
+ parent_content_url_.spec().c_str(),
+ escaped_resource_id.c_str()));
+ return AddStandardUrlParams(edit_url);
+}
+
+URLFetcher::RequestType
+RemoveResourceFromDirectoryOperation::GetRequestType() const {
+ return URLFetcher::DELETE_REQUEST;
zel 2012/03/12 20:40:40 will this delete the file completely or just remov
Ben Chan 2012/03/13 00:29:21 It only removes the file from collection, not the
+}
+
+std::vector<std::string>
+RemoveResourceFromDirectoryOperation::GetExtraRequestHeaders() const {
+ std::vector<std::string> headers;
+ headers.push_back(kIfMatchAllHeader);
+ return headers;
+}
+
//=========================== InitiateUploadOperation ==========================
class InitiateUploadOperation
@@ -1203,6 +1459,48 @@
directory_name));
}
+void DocumentsService::CopyDocument(const GURL& document_url,
+ const FilePath::StringType& new_name,
+ const GetDataCallback& callback) {
+ StartOperationOnUIThread(
+ new CopyDocumentOperation(operation_registry_.get(), profile_, callback,
+ document_url, new_name));
+}
+
+void DocumentsService::RenameResource(const GURL& resource_url,
+ const FilePath::StringType& new_name,
+ const EntryActionCallback& callback) {
+ StartOperationOnUIThread(
+ new RenameResourceOperation(operation_registry_.get(), profile_, callback,
+ resource_url, new_name));
+}
+
+void DocumentsService::AddResourceToDirectory(
+ const GURL& parent_content_url,
+ const GURL& resource_url,
+ const EntryActionCallback& callback) {
+ StartOperationOnUIThread(
+ new AddResourceToDirectoryOperation(operation_registry_.get(),
+ profile_,
+ callback,
+ parent_content_url,
+ resource_url));
+}
+
+void DocumentsService::RemoveResourceFromDirectory(
+ const GURL& parent_content_url,
+ const GURL& resource_url,
+ const std::string& resource_id,
+ const EntryActionCallback& callback) {
+ StartOperationOnUIThread(
+ new RemoveResourceFromDirectoryOperation(operation_registry_.get(),
+ profile_,
+ callback,
+ parent_content_url,
+ resource_url,
+ resource_id));
+}
+
void DocumentsService::InitiateUpload(const InitiateUploadParams& params,
const InitiateUploadCallback& callback) {
if (params.resumable_create_media_link.is_empty()) {

Powered by Google App Engine
This is Rietveld 408576698