Home | History | Annotate | Download | only in extensions
      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
      3 // found in the LICENSE file.
      4 
      5 #include "extension_info_private_api_chromeos.h"
      6 
      7 #include "base/values.h"
      8 #include "chrome/browser/chromeos/cros/cros_library.h"
      9 #include "chrome/browser/chromeos/cros/network_library.h"
     10 #include "chrome/browser/chromeos/system_access.h"
     11 
     12 using chromeos::CrosLibrary;
     13 using chromeos::NetworkLibrary;
     14 
     15 namespace {
     16 
     17 // Key which corresponds to the HWID setting.
     18 const char kPropertyHWID[] = "hwid";
     19 
     20 // Key which corresponds to the home provider property.
     21 const char kPropertyHomeProvider[] = "homeProvider";
     22 
     23 }  // namespace
     24 
     25 GetChromeosInfoFunction::GetChromeosInfoFunction() {
     26 }
     27 
     28 GetChromeosInfoFunction::~GetChromeosInfoFunction() {
     29 }
     30 
     31 bool GetChromeosInfoFunction::RunImpl() {
     32   ListValue* list = NULL;
     33   EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list));
     34   scoped_ptr<DictionaryValue> result(new DictionaryValue());
     35   for (size_t i = 0; i < list->GetSize(); ++i) {
     36     std::string property_name;
     37     EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name));
     38     std::string value;
     39     if (GetValue(property_name, &value))
     40       result->Set(property_name, Value::CreateStringValue(value));
     41   }
     42   result_.reset(result.release());
     43   SendResponse(true);
     44   return true;
     45 }
     46 
     47 bool GetChromeosInfoFunction::GetValue(const std::string& property_name,
     48                                        std::string* value) {
     49   value->clear();
     50   if (property_name == kPropertyHWID) {
     51     chromeos::SystemAccess* system = chromeos::SystemAccess::GetInstance();
     52     system->GetMachineStatistic(kPropertyHWID, value);
     53   } else if (property_name == kPropertyHomeProvider) {
     54     if (CrosLibrary::Get()->EnsureLoaded()) {
     55       NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
     56       (*value) = netlib->GetCellularHomeCarrierId();
     57     } else {
     58       LOG(ERROR) << "CrosLibrary can't be loaded.";
     59     }
     60   } else {
     61     LOG(ERROR) << "Unknown property request: " << property_name;
     62     return false;
     63   }
     64   return true;
     65 }
     66