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

Unified Diff: chrome/browser/extensions/extension_info_private_api_chromeos.cc

Issue 6899021: HWID and VPD values should be accessible via SystemAccess::GetMachineStatistic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit_test Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_info_private_api_chromeos.cc
diff --git a/chrome/browser/extensions/extension_info_private_api_chromeos.cc b/chrome/browser/extensions/extension_info_private_api_chromeos.cc
index f55ce9a96b2fff0fc50cdb19a42eb1286d334860..f5d441def5fd1470e584fbd86c60e2e994c2a70e 100644
--- a/chrome/browser/extensions/extension_info_private_api_chromeos.cc
+++ b/chrome/browser/extensions/extension_info_private_api_chromeos.cc
@@ -4,16 +4,10 @@
#include "extension_info_private_api_chromeos.h"
-#include <map>
-#include "base/threading/non_thread_safe.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
-#include "chrome/browser/chromeos/customization_document.h"
-#include "chrome/common/extensions/extension_error_utils.h"
-#include "content/browser/browser_thread.h"
+#include "chrome/browser/chromeos/system_access.h"
using chromeos::CrosLibrary;
using chromeos::NetworkLibrary;
@@ -26,86 +20,37 @@ const char kPropertyHWID[] = "hwid";
// Key which corresponds to the home provider property.
const char kPropertyHomeProvider[] = "homeProvider";
-// Path to OEM partner startup customization manifest.
-const char kStartupCustomizationManifestPath[] =
- "/opt/oem/etc/startup_manifest.json";
-
-// Keeps cached values to avoid unnecessary file operations. Should only be
-// used from the UI thread.
-class CachedProperties : base::NonThreadSafe {
- public:
- ~CachedProperties();
- // Gets value for the property with the given name. Return whether value has
- // been found.
- bool GetValue(const std::string& property_name, std::string* value);
-
- // Updates cached properties with the given item.
- void Update(const std::pair<std::string, std::string>& item);
-
- private:
- typedef std::map<std::string, std::string> PropertyMap;
- PropertyMap cache_;
-};
-
-CachedProperties::~CachedProperties() {
- // It is safe to delete this class on any thread since class is used
- // through LazyInstance.
- DetachFromThread();
-}
-
-bool CachedProperties::GetValue(const std::string& property_name,
- std::string* value) {
- DCHECK(CalledOnValidThread());
- PropertyMap::iterator iter = cache_.find(property_name);
- if (iter != cache_.end()) {
- (*value) = iter->second;
- return true;
- }
- return false;
-}
+} // namespace
-// Updates cached properties with the given value of the property.
-void CachedProperties::Update(
- const std::pair<std::string, std::string>& item) {
- DCHECK(CalledOnValidThread());
- cache_.insert(item);
+GetChromeosInfoFunction::GetChromeosInfoFunction() {
}
-// Provides customization properties. Should be used only on the FILE thread.
-class CustomizationData : base::NonThreadSafe {
- public:
- CustomizationData();
- ~CustomizationData();
-
- // Gets value for the property with the given name. Return whether value has
- // been found.
- bool GetValue(const std::string& property_name, std::string* value);
-
- private:
- // Keeps customization document from which properties are extracted.
- chromeos::StartupCustomizationDocument document_;
-
- DISALLOW_COPY_AND_ASSIGN(CustomizationData);
-};
-
-CustomizationData::CustomizationData() {
- DCHECK(CalledOnValidThread());
- document_.LoadManifestFromFile(FilePath(kStartupCustomizationManifestPath));
+GetChromeosInfoFunction::~GetChromeosInfoFunction() {
}
-CustomizationData::~CustomizationData() {
- // It is safe to delete this class on any thread since class is used
- // through LazyInstance.
- DetachFromThread();
+bool GetChromeosInfoFunction::RunImpl() {
+ ListValue* list = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list));
+ scoped_ptr<DictionaryValue> result(new DictionaryValue());
+ for (size_t i = 0; i < list->GetSize(); ++i) {
+ std::string property_name;
+ EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name));
+ std::string value;
+ if (GetValue(property_name, &value))
+ result->Set(property_name, Value::CreateStringValue(value));
+ }
+ result_.reset(result.release());
+ SendResponse(true);
+ return true;
}
-bool CustomizationData::GetValue(const std::string& property_name,
- std::string* value) {
- DCHECK(CalledOnValidThread());
+bool GetChromeosInfoFunction::GetValue(const std::string& property_name,
+ std::string* value) {
+ value->clear();
if (property_name == kPropertyHWID) {
- (*value) = document_.GetHWID();
+ chromeos::SystemAccess* system = chromeos::SystemAccess::GetInstance();
+ system->GetMachineStatistic(kPropertyHWID, value);
} else if (property_name == kPropertyHomeProvider) {
- (*value) = "";
if (CrosLibrary::Get()->EnsureLoaded()) {
NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
const chromeos::NetworkDevice* device = netlib->FindCellularDevice();
@@ -125,73 +70,3 @@ bool CustomizationData::GetValue(const std::string& property_name,
}
return true;
}
-
-// Shared instances.
-base::LazyInstance<CachedProperties> g_cached_properties(
- base::LINKER_INITIALIZED);
-base::LazyInstance<CustomizationData> g_customization(base::LINKER_INITIALIZED);
-
-} // namespace
-
-GetChromeosInfoFunction::GetChromeosInfoFunction()
- : result_dictionary_(new DictionaryValue) {
-}
-
-GetChromeosInfoFunction::~GetChromeosInfoFunction() {
-}
-
-bool GetChromeosInfoFunction::RunImpl() {
- ListValue* list = NULL;
- EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list));
- for (size_t i = 0; i < list->GetSize(); ++i) {
- std::string property_name;
- EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name));
- std::string value;
- if (g_cached_properties.Get().GetValue(property_name, &value)) {
- result_dictionary_->Set(property_name, Value::CreateStringValue(value));
- } else {
- properties_.push_back(property_name);
- }
- }
-
- if (!properties_.empty()) {
- // This will calls us back on UI thread.
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- NewRunnableMethod(this,
- &GetChromeosInfoFunction::LoadValues));
- } else {
- // Early answer is ready.
- result_.reset(result_dictionary_.release());
- SendResponse(true);
- }
- return true;
-}
-
-void GetChromeosInfoFunction::RespondOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- for (size_t i = 0; i < new_results_.size(); ++i) {
- result_dictionary_->Set(new_results_[i].first,
- Value::CreateStringValue(new_results_[i].second));
- g_cached_properties.Get().Update(new_results_[i]);
- }
- result_.reset(result_dictionary_.release());
- SendResponse(true);
-}
-
-void GetChromeosInfoFunction::LoadValues() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- new_results_.clear();
- for (size_t i = 0; i < properties_.size(); ++i) {
- std::string value;
- if (g_customization.Get().GetValue(properties_[i], &value))
- new_results_.push_back(std::make_pair(properties_[i], value));
- }
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- NewRunnableMethod(
- this,
- &GetChromeosInfoFunction::RespondOnUIThread));
-}

Powered by Google App Engine
This is Rietveld 408576698