Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/browser/google_apis/drive_api_operations.h" | 5 #include "chrome/browser/google_apis/drive_api_operations.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | |
| 8 #include "base/values.h" | |
| 9 | |
| 7 namespace google_apis { | 10 namespace google_apis { |
| 11 namespace { | |
| 12 | |
| 13 const char kContentTypeApplicationJson[] = "application/json"; | |
| 14 const char kDirectoryMimeType[] = "application/vnd.google-apps.folder"; | |
| 15 | |
| 16 } // namespace | |
| 8 | 17 |
| 9 //============================== GetAboutOperation ============================= | 18 //============================== GetAboutOperation ============================= |
| 10 | 19 |
| 11 GetAboutOperation::GetAboutOperation( | 20 GetAboutOperation::GetAboutOperation( |
| 12 OperationRegistry* registry, | 21 OperationRegistry* registry, |
| 13 net::URLRequestContextGetter* url_request_context_getter, | 22 net::URLRequestContextGetter* url_request_context_getter, |
| 14 const DriveApiUrlGenerator& url_generator, | 23 const DriveApiUrlGenerator& url_generator, |
| 15 const GetDataCallback& callback) | 24 const GetDataCallback& callback) |
| 16 : GetDataOperation(registry, url_request_context_getter, callback), | 25 : GetDataOperation(registry, url_request_context_getter, callback), |
| 17 url_generator_(url_generator) { | 26 url_generator_(url_generator) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 file_id_(file_id) { | 108 file_id_(file_id) { |
| 100 DCHECK(!callback.is_null()); | 109 DCHECK(!callback.is_null()); |
| 101 } | 110 } |
| 102 | 111 |
| 103 GetFileOperation::~GetFileOperation() {} | 112 GetFileOperation::~GetFileOperation() {} |
| 104 | 113 |
| 105 GURL GetFileOperation::GetURL() const { | 114 GURL GetFileOperation::GetURL() const { |
| 106 return url_generator_.GetFileUrl(file_id_); | 115 return url_generator_.GetFileUrl(file_id_); |
| 107 } | 116 } |
| 108 | 117 |
| 118 namespace drive { | |
| 119 | |
| 120 //========================== CreateDirectoryOperation ========================== | |
|
satorux1
2013/01/29 04:51:41
nit: add a blank line here.
hidehiko
2013/01/29 05:40:49
Done.
| |
| 121 CreateDirectoryOperation::CreateDirectoryOperation( | |
| 122 OperationRegistry* registry, | |
| 123 net::URLRequestContextGetter* url_request_context_getter, | |
| 124 const DriveApiUrlGenerator& url_generator, | |
| 125 const std::string& parent_resource_id, | |
| 126 const std::string& directory_name, | |
| 127 const GetDataCallback& callback) | |
| 128 : GetDataOperation(registry, url_request_context_getter, callback), | |
| 129 url_generator_(url_generator), | |
| 130 parent_resource_id_(parent_resource_id), | |
| 131 directory_name_(directory_name) { | |
| 132 DCHECK(!callback.is_null()); | |
| 133 } | |
| 134 | |
| 135 CreateDirectoryOperation::~CreateDirectoryOperation() {} | |
| 136 | |
| 137 GURL CreateDirectoryOperation::GetURL() const { | |
| 138 if (parent_resource_id_.empty() || directory_name_.empty()) { | |
| 139 return GURL(); | |
| 140 } | |
| 141 return url_generator_.GetFilelistUrl(GURL(), ""); | |
| 142 } | |
| 143 | |
| 144 net::URLFetcher::RequestType CreateDirectoryOperation::GetRequestType() const { | |
| 145 return net::URLFetcher::POST; | |
| 146 } | |
| 147 | |
| 148 bool CreateDirectoryOperation::GetContentData(std::string* upload_content_type, | |
| 149 std::string* upload_content) { | |
| 150 *upload_content_type = kContentTypeApplicationJson; | |
| 151 | |
| 152 base::DictionaryValue root; | |
| 153 root.SetString("title", directory_name_); | |
| 154 { | |
| 155 base::DictionaryValue* parent_value = new base::DictionaryValue; | |
| 156 parent_value->SetString("id", parent_resource_id_); | |
| 157 base::ListValue* parent_list_value = new base::ListValue; | |
| 158 parent_list_value->Append(parent_value); | |
| 159 root.Set("parents", parent_list_value); | |
| 160 } | |
| 161 root.SetString("mimeType", kDirectoryMimeType); | |
| 162 | |
| 163 base::JSONWriter::Write(&root, upload_content); | |
| 164 | |
| 165 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", [" | |
| 166 << *upload_content << "]"; | |
| 167 return true; | |
| 168 } | |
| 169 | |
| 170 } // namespace drive | |
| 109 } // namespace google_apis | 171 } // namespace google_apis |
| OLD | NEW |