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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/remove_operation.cc

Issue 11106007: drive: Rename 'gdata' namespace to 'drive' in chrome/browser/chromeos/drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "chrome/browser/chromeos/drive/drive.pb.h" 10 #include "chrome/browser/chromeos/drive/drive.pb.h"
11 #include "chrome/browser/chromeos/drive/drive_cache.h" 11 #include "chrome/browser/chromeos/drive/drive_cache.h"
12 #include "chrome/browser/chromeos/drive/drive_file_system.h" 12 #include "chrome/browser/chromeos/drive/drive_file_system.h"
13 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 13 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
14 #include "chrome/browser/chromeos/drive/drive_service_interface.h" 14 #include "chrome/browser/chromeos/drive/drive_service_interface.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 16
17 using content::BrowserThread; 17 using content::BrowserThread;
18 18
19 namespace gdata { 19 namespace drive {
20 20
21 namespace { 21 namespace {
22 int kMaxRetries = 5; 22 int kMaxRetries = 5;
23 } 23 }
24 24
25 namespace file_system { 25 namespace file_system {
26 26
27 RemoveOperation::RemoveOperation(DriveServiceInterface* drive_service, 27 RemoveOperation::RemoveOperation(DriveServiceInterface* drive_service,
28 DriveFileSystem* file_system, 28 DriveFileSystem* file_system,
29 DriveCache* cache) 29 DriveCache* cache)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 weak_ptr_factory_.GetWeakPtr(), 85 weak_ptr_factory_.GetWeakPtr(),
86 callback, 86 callback,
87 retry_count + 1, 87 retry_count + 1,
88 base::Passed(&entry_proto))); 88 base::Passed(&entry_proto)));
89 } 89 }
90 90
91 void RemoveOperation::RetryIfNeeded( 91 void RemoveOperation::RetryIfNeeded(
92 const FileOperationCallback& callback, 92 const FileOperationCallback& callback,
93 int retry_count, 93 int retry_count,
94 scoped_ptr<DriveEntryProto> entry_proto, 94 scoped_ptr<DriveEntryProto> entry_proto,
95 GDataErrorCode status, 95 gdata::GDataErrorCode status,
96 const GURL& /* document_url */) { 96 const GURL& /* document_url */) {
97 // If the call failed due to flooding the server, and we haven't hit the 97 // If the call failed due to flooding the server, and we haven't hit the
98 // maximum number of retries, throttle and retry. 98 // maximum number of retries, throttle and retry.
99 // 99 //
100 // TODO(zork): Move this retry logic into the scheduler when it is completed. 100 // TODO(zork): Move this retry logic into the scheduler when it is completed.
101 if ((status == HTTP_SERVICE_UNAVAILABLE || 101 if ((status == gdata::HTTP_SERVICE_UNAVAILABLE ||
102 status == HTTP_INTERNAL_SERVER_ERROR) && 102 status == gdata::HTTP_INTERNAL_SERVER_ERROR) &&
103 retry_count < kMaxRetries) { 103 retry_count < kMaxRetries) {
104 base::TimeDelta delay = 104 base::TimeDelta delay =
105 base::TimeDelta::FromSeconds(pow(2, retry_count)) + 105 base::TimeDelta::FromSeconds(pow(2, retry_count)) +
106 base::TimeDelta::FromMilliseconds(base::RandInt(0, 1000)); 106 base::TimeDelta::FromMilliseconds(base::RandInt(0, 1000));
107 107
108 VLOG(1) << "Throttling for " << delay.InMillisecondsF(); 108 VLOG(1) << "Throttling for " << delay.InMillisecondsF();
109 const bool posted = base::MessageLoopProxy::current()->PostDelayedTask( 109 const bool posted = base::MessageLoopProxy::current()->PostDelayedTask(
110 FROM_HERE, 110 FROM_HERE,
111 base::Bind(&RemoveOperation::DoDelete, 111 base::Bind(&RemoveOperation::DoDelete,
112 weak_ptr_factory_.GetWeakPtr(), 112 weak_ptr_factory_.GetWeakPtr(),
113 callback, 113 callback,
114 retry_count, 114 retry_count,
115 base::Passed(&entry_proto)), 115 base::Passed(&entry_proto)),
116 delay); 116 delay);
117 DCHECK(posted); 117 DCHECK(posted);
118 } else { 118 } else {
119 // If the operation completed, or we hit max retries, continue. 119 // If the operation completed, or we hit max retries, continue.
120 RemoveResourceLocally(callback, 120 RemoveResourceLocally(callback,
121 entry_proto->resource_id(), 121 entry_proto->resource_id(),
122 status); 122 status);
123 } 123 }
124 } 124 }
125 125
126 void RemoveOperation::RemoveResourceLocally( 126 void RemoveOperation::RemoveResourceLocally(
127 const FileOperationCallback& callback, 127 const FileOperationCallback& callback,
128 const std::string& resource_id, 128 const std::string& resource_id,
129 GDataErrorCode status) { 129 gdata::GDataErrorCode status) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
131 DCHECK(!callback.is_null()); 131 DCHECK(!callback.is_null());
132 132
133 DriveFileError error = util::GDataToDriveFileError(status); 133 DriveFileError error = util::GDataToDriveFileError(status);
134 if (error != DRIVE_FILE_OK) { 134 if (error != DRIVE_FILE_OK) {
135 callback.Run(error); 135 callback.Run(error);
136 return; 136 return;
137 } 137 }
138 138
139 file_system_->ResourceMetadata()->RemoveEntryFromParent( 139 file_system_->ResourceMetadata()->RemoveEntryFromParent(
(...skipping 10 matching lines...) Expand all
150 DriveFileError error, 150 DriveFileError error,
151 const FilePath& directory_path) { 151 const FilePath& directory_path) {
152 if (error == DRIVE_FILE_OK) 152 if (error == DRIVE_FILE_OK)
153 file_system_->OnDirectoryChanged(directory_path); 153 file_system_->OnDirectoryChanged(directory_path);
154 154
155 if (!callback.is_null()) 155 if (!callback.is_null())
156 callback.Run(error); 156 callback.Run(error);
157 } 157 }
158 158
159 } // namespace file_system 159 } // namespace file_system
160 } // namespace gdata 160 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698