1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "chrome/browser/sync_file_system/logger.h"
11 namespace sync_file_system {
15 // A command-line switch to disable Drive API and to make Sync FileSystem API
16 // work on WAPI (http://crbug.com/234557)
17 // TODO(nhiroki): this command-line switch should be temporary.
18 const char kDisableDriveAPI[] = "disable-drive-api-for-syncfs";
20 bool is_drive_api_disabled = false;
24 SyncStatusCode GDataErrorCodeToSyncStatusCode(
25 google_apis::GDataErrorCode error) {
26 // NOTE: Please update DriveFileSyncService::UpdateServiceState when you add
27 // more error code mapping.
29 case google_apis::HTTP_SUCCESS:
30 case google_apis::HTTP_CREATED:
31 case google_apis::HTTP_NO_CONTENT:
32 case google_apis::HTTP_FOUND:
33 return SYNC_STATUS_OK;
35 case google_apis::HTTP_NOT_MODIFIED:
36 return SYNC_STATUS_NOT_MODIFIED;
38 case google_apis::HTTP_CONFLICT:
39 case google_apis::HTTP_PRECONDITION:
40 return SYNC_STATUS_HAS_CONFLICT;
42 case google_apis::HTTP_UNAUTHORIZED:
43 return SYNC_STATUS_AUTHENTICATION_FAILED;
45 case google_apis::GDATA_NO_CONNECTION:
46 return SYNC_STATUS_NETWORK_ERROR;
48 case google_apis::HTTP_INTERNAL_SERVER_ERROR:
49 case google_apis::HTTP_BAD_GATEWAY:
50 case google_apis::HTTP_SERVICE_UNAVAILABLE:
51 case google_apis::GDATA_CANCELLED:
52 case google_apis::GDATA_NOT_READY:
53 return SYNC_STATUS_SERVICE_TEMPORARILY_UNAVAILABLE;
55 case google_apis::HTTP_NOT_FOUND:
56 return SYNC_FILE_ERROR_NOT_FOUND;
58 case google_apis::GDATA_FILE_ERROR:
59 return SYNC_FILE_ERROR_FAILED;
61 case google_apis::HTTP_FORBIDDEN:
62 return SYNC_STATUS_ACCESS_FORBIDDEN;
64 case google_apis::HTTP_RESUME_INCOMPLETE:
65 case google_apis::HTTP_BAD_REQUEST:
66 case google_apis::HTTP_LENGTH_REQUIRED:
67 case google_apis::HTTP_NOT_IMPLEMENTED:
68 case google_apis::GDATA_PARSE_ERROR:
69 case google_apis::GDATA_OTHER_ERROR:
70 return SYNC_STATUS_FAILED;
72 case google_apis::GDATA_NO_SPACE:
73 return SYNC_FILE_ERROR_NO_SPACE;
76 // There's a case where DriveService layer returns GDataErrorCode==-1
77 // when network is unavailable. (http://crbug.com/223042)
78 // TODO(kinuko,nhiroki): We should identify from where this undefined error
81 return SYNC_STATUS_NETWORK_ERROR;
83 util::Log(logging::LOG_WARNING,
85 "Got unexpected error: %d",
86 static_cast<int>(error));
87 return SYNC_STATUS_FAILED;
90 void SetDisableDriveAPI(bool flag) {
91 is_drive_api_disabled = flag;
94 bool IsDriveAPIDisabled() {
95 return is_drive_api_disabled ||
96 CommandLine::ForCurrentProcess()->HasSwitch(kDisableDriveAPI);
99 ScopedDisableDriveAPI::ScopedDisableDriveAPI()
100 : was_disabled_(IsDriveAPIDisabled()) {
101 SetDisableDriveAPI(true);
104 ScopedDisableDriveAPI::~ScopedDisableDriveAPI() {
105 DCHECK(IsDriveAPIDisabled());
106 SetDisableDriveAPI(was_disabled_);
109 } // namespace sync_file_system