Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/system/system_api.h" | 5 #include "chrome/browser/extensions/system/system_api.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 | 11 |
| 12 #if defined(OS_CHROMEOS) | |
| 13 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | |
| 14 #include "chrome/browser/chromeos/dbus/update_engine_client.h" | |
| 15 #else | |
| 16 #include "chrome/browser/upgrade_detector.h" | |
| 17 #endif | |
| 18 | |
| 12 namespace { | 19 namespace { |
| 13 | 20 |
| 14 // Maps prefs::kIncognitoModeAvailability values (0 = enabled, ...) | 21 // Maps prefs::kIncognitoModeAvailability values (0 = enabled, ...) |
| 15 // to strings exposed to extensions. | 22 // to strings exposed to extensions. |
| 16 const char* kIncognitoModeAvailabilityStrings[] = { | 23 const char* kIncognitoModeAvailabilityStrings[] = { |
| 17 "enabled", | 24 "enabled", |
| 18 "disabled", | 25 "disabled", |
| 19 "forced" | 26 "forced" |
| 20 }; | 27 }; |
| 21 | 28 |
| 29 // Property keys. | |
| 30 const char kStateKey[] = "state"; | |
| 31 const char kDownloadProgressKey[] = "download_progress"; | |
| 32 | |
| 33 // System update states. | |
| 34 const char kNotAvailableState[] = "NotAvailable"; | |
| 35 const char kUpdatingState[] = "Updating"; | |
| 36 const char kNeedRestartState[] = "NeedRestart"; | |
| 37 | |
| 22 } // namespace | 38 } // namespace |
| 23 | 39 |
| 24 namespace extensions { | 40 namespace extensions { |
| 25 | 41 |
| 26 GetIncognitoModeAvailabilityFunction::~GetIncognitoModeAvailabilityFunction() { | |
| 27 } | |
| 28 | |
| 29 bool GetIncognitoModeAvailabilityFunction::RunImpl() { | 42 bool GetIncognitoModeAvailabilityFunction::RunImpl() { |
| 30 PrefService* prefs = profile_->GetPrefs(); | 43 PrefService* prefs = profile_->GetPrefs(); |
| 31 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); | 44 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); |
| 32 EXTENSION_FUNCTION_VALIDATE( | 45 EXTENSION_FUNCTION_VALIDATE( |
| 33 value >= 0 && | 46 value >= 0 && |
| 34 value < static_cast<int>(arraysize(kIncognitoModeAvailabilityStrings))); | 47 value < static_cast<int>(arraysize(kIncognitoModeAvailabilityStrings))); |
| 35 result_.reset( | 48 result_.reset( |
| 36 Value::CreateStringValue(kIncognitoModeAvailabilityStrings[value])); | 49 Value::CreateStringValue(kIncognitoModeAvailabilityStrings[value])); |
| 37 return true; | 50 return true; |
| 38 } | 51 } |
| 39 | 52 |
| 53 bool GetUpdateStatusFunction::RunImpl() { | |
| 54 std::string state; | |
| 55 double download_progress = 0; | |
| 56 #if defined(OS_CHROMEOS) | |
| 57 // With UpdateEngineClient, we can provide more detailed information about | |
| 58 // system updates on ChromeOS. | |
| 59 const chromeos::UpdateEngineClient::Status status = | |
| 60 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> | |
| 61 GetLastStatus(); | |
| 62 // |download_progress| is set to 1 after download finishes | |
| 63 // (i.e. verify, finalize and need-reboot phase) to indicate the progress | |
| 64 // even though |status.download_progress| is 0 in these phases. | |
| 65 switch (status.status) { | |
| 66 case chromeos::UpdateEngineClient::UPDATE_STATUS_ERROR: | |
| 67 state = kNotAvailableState; | |
| 68 break; | |
| 69 case chromeos::UpdateEngineClient::UPDATE_STATUS_IDLE: | |
| 70 state = kNotAvailableState; | |
| 71 break; | |
| 72 case chromeos::UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: | |
| 73 state = kNotAvailableState; | |
| 74 break; | |
| 75 case chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | |
| 76 state = kUpdatingState; | |
| 77 break; | |
| 78 case chromeos::UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | |
| 79 state = kUpdatingState; | |
| 80 download_progress = status.download_progress; | |
| 81 break; | |
| 82 case chromeos::UpdateEngineClient::UPDATE_STATUS_VERIFYING: | |
| 83 state = kUpdatingState; | |
| 84 download_progress = 1; | |
| 85 break; | |
| 86 case chromeos::UpdateEngineClient::UPDATE_STATUS_FINALIZING: | |
| 87 state = kUpdatingState; | |
| 88 download_progress = 1; | |
| 89 break; | |
| 90 case chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | |
| 91 state = kNeedRestartState; | |
| 92 download_progress = 1; | |
| 93 break; | |
| 94 case chromeos::UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: | |
| 95 state = kNotAvailableState; | |
| 96 break; | |
| 97 } | |
| 98 #else | |
|
battre
2011/12/14 09:21:27
In this branch |state| can be empty. I think it sh
hashimoto
2011/12/14 09:40:02
You're right, thanks.
Fixed.
| |
| 99 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | |
| 100 state = kNeedRestartState; | |
| 101 download_progress = 1; | |
| 102 } | |
| 103 #endif | |
| 104 DictionaryValue* dict = new DictionaryValue(); | |
| 105 dict->SetString(kStateKey, state); | |
| 106 dict->SetDouble(kDownloadProgressKey, download_progress); | |
| 107 result_.reset(dict); | |
| 108 | |
| 109 return true; | |
| 110 } | |
| 111 | |
| 40 } // namespace extensions | 112 } // namespace extensions |
| OLD | NEW |