OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/extensions/file_manager/private_api_drive.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" | 9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" |
10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
22 #include "webkit/common/fileapi/file_system_info.h" | 22 #include "webkit/common/fileapi/file_system_info.h" |
23 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "webkit/common/fileapi/file_system_util.h" |
24 | 24 |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 namespace { | 28 namespace { |
29 | 29 |
30 // List of connection types of drive. | 30 // List of connection types of drive. |
31 // Keep this in sync with the DriveConnectionType in volume_manager.js. | 31 // Keep this in sync with the DriveConnectionType in common/js/util.js. |
32 const char kDriveConnectionTypeOffline[] = "offline"; | 32 const char kDriveConnectionTypeOffline[] = "offline"; |
33 const char kDriveConnectionTypeMetered[] = "metered"; | 33 const char kDriveConnectionTypeMetered[] = "metered"; |
34 const char kDriveConnectionTypeOnline[] = "online"; | 34 const char kDriveConnectionTypeOnline[] = "online"; |
35 | 35 |
36 // List of reasons of kDriveConnectionType*. | 36 // List of reasons of kDriveConnectionType*. |
37 // Keep this in sync with the DriveConnectionReason in volume_manager.js. | 37 // Keep this in sync with the DriveConnectionReason in common/js/util.js. |
38 const char kDriveConnectionReasonNotReady[] = "not_ready"; | 38 const char kDriveConnectionReasonNotReady[] = "not_ready"; |
39 const char kDriveConnectionReasonNoNetwork[] = "no_network"; | 39 const char kDriveConnectionReasonNoNetwork[] = "no_network"; |
40 const char kDriveConnectionReasonNoService[] = "no_service"; | 40 const char kDriveConnectionReasonNoService[] = "no_service"; |
41 | 41 |
42 // Copies properties from |entry_proto| to |properties|. | 42 // Copies properties from |entry_proto| to |properties|. |
43 void FillDriveEntryPropertiesValue( | 43 void FillDriveEntryPropertiesValue( |
44 const drive::ResourceEntry& entry_proto, | 44 const drive::ResourceEntry& entry_proto, |
45 api::file_browser_private::DriveEntryProperties* properties) { | 45 api::file_browser_private::DriveEntryProperties* properties) { |
46 properties->shared_with_me.reset(new bool(entry_proto.shared_with_me())); | 46 properties->shared_with_me.reset(new bool(entry_proto.shared_with_me())); |
47 | 47 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 result_dict->SetString("highlightedBaseName", | 503 result_dict->SetString("highlightedBaseName", |
504 results->at(i).highlighted_base_name); | 504 results->at(i).highlighted_base_name); |
505 results_list->Append(result_dict); | 505 results_list->Append(result_dict); |
506 } | 506 } |
507 | 507 |
508 SetResult(results_list); | 508 SetResult(results_list); |
509 SendResponse(true); | 509 SendResponse(true); |
510 } | 510 } |
511 | 511 |
512 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() { | 512 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() { |
513 drive::DriveServiceInterface* const drive_service = | |
514 drive::util::GetDriveServiceByProfile(GetProfile()); | |
515 | |
516 api::file_browser_private::GetDriveConnectionState::Results::Result result; | 513 api::file_browser_private::GetDriveConnectionState::Results::Result result; |
517 | 514 |
518 const bool ready = drive_service && drive_service->CanSendRequest(); | 515 switch (drive::util::GetDriveConnectionStatus(GetProfile())) { |
519 const bool is_connection_cellular = | 516 case drive::util::DRIVE_DISCONNECTED_NOSERVICE: |
520 net::NetworkChangeNotifier::IsConnectionCellular( | 517 result.type = kDriveConnectionTypeOffline; |
521 net::NetworkChangeNotifier::GetConnectionType()); | 518 result.reason.reset(new std::string(kDriveConnectionReasonNoService)); |
522 | 519 break; |
523 if (net::NetworkChangeNotifier::IsOffline() || !ready) { | 520 case drive::util::DRIVE_DISCONNECTED_NONETWORK: |
524 result.type = kDriveConnectionTypeOffline; | 521 result.type = kDriveConnectionTypeOffline; |
525 if (net::NetworkChangeNotifier::IsOffline()) | 522 result.reason.reset(new std::string(kDriveConnectionReasonNoNetwork)); |
526 result.reasons.push_back(kDriveConnectionReasonNoNetwork); | 523 break; |
527 if (!ready) | 524 case drive::util::DRIVE_DISCONNECTED_NOTREADY: |
528 result.reasons.push_back(kDriveConnectionReasonNotReady); | 525 result.type = kDriveConnectionTypeOffline; |
529 if (!drive_service) | 526 result.reason.reset(new std::string(kDriveConnectionReasonNotReady)); |
530 result.reasons.push_back(kDriveConnectionReasonNoService); | 527 break; |
531 } else if ( | 528 case drive::util::DRIVE_CONNECTED_METERED: |
532 is_connection_cellular && | 529 result.type = kDriveConnectionTypeMetered; |
533 GetProfile()->GetPrefs()->GetBoolean( | 530 break; |
534 prefs::kDisableDriveOverCellular)) { | 531 case drive::util::DRIVE_CONNECTED: |
535 result.type = kDriveConnectionTypeMetered; | 532 result.type = kDriveConnectionTypeOnline; |
536 } else { | 533 break; |
537 result.type = kDriveConnectionTypeOnline; | |
538 } | 534 } |
539 | 535 |
540 results_ = api::file_browser_private::GetDriveConnectionState::Results:: | 536 results_ = api::file_browser_private::GetDriveConnectionState::Results:: |
541 Create(result); | 537 Create(result); |
542 | 538 |
543 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); | 539 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); |
544 return true; | 540 return true; |
545 } | 541 } |
546 | 542 |
547 bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() { | 543 bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 error_ = "Share Url for this item is not available."; | 606 error_ = "Share Url for this item is not available."; |
611 SendResponse(false); | 607 SendResponse(false); |
612 return; | 608 return; |
613 } | 609 } |
614 | 610 |
615 SetResult(new base::StringValue(share_url.spec())); | 611 SetResult(new base::StringValue(share_url.spec())); |
616 SendResponse(true); | 612 SendResponse(true); |
617 } | 613 } |
618 | 614 |
619 } // namespace extensions | 615 } // namespace extensions |
OLD | NEW |