Home | History | Annotate | Download | only in cros
      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 "chrome/browser/chromeos/cros/cros_library_loader.h"
      6 
      7 #include <dlfcn.h>
      8 
      9 #include "base/file_path.h"
     10 #include "base/metrics/histogram.h"
     11 #include "base/logging.h"
     12 #include "base/path_service.h"
     13 #include "chrome/common/chrome_paths.h"
     14 #include "third_party/cros/chromeos_cros_api.h"
     15 
     16 namespace chromeos {
     17 
     18 namespace {
     19 
     20 void addLibcrosTimeHistogram(const char* name, const base::TimeDelta& delta) {
     21   static const base::TimeDelta min_time = base::TimeDelta::FromMilliseconds(1);
     22   static const base::TimeDelta max_time = base::TimeDelta::FromSeconds(1);
     23   const size_t bucket_count(10);
     24   DCHECK(name);
     25   base::Histogram* counter = base::Histogram::FactoryTimeGet(
     26       std::string(name),
     27       min_time,
     28       max_time,
     29       bucket_count,
     30       base::Histogram::kNoFlags);
     31   counter->AddTime(delta);
     32   VLOG(1) << "Cros Time: " << name << ": " << delta.InMilliseconds() << "ms.";
     33 }
     34 
     35 }  // namespace
     36 
     37 bool CrosLibraryLoader::Load(std::string* load_error_string) {
     38   bool loaded = false;
     39   FilePath path;
     40   if (PathService::Get(chrome::FILE_CHROMEOS_API, &path)) {
     41     loaded = LoadLibcros(path.value().c_str(), *load_error_string);
     42     if (loaded)
     43       SetLibcrosTimeHistogramFunction(addLibcrosTimeHistogram);
     44   }
     45 
     46   if (!loaded) {
     47     LOG(ERROR) << "Problem loading chromeos shared object: "
     48                << *load_error_string;
     49   }
     50   return loaded;
     51 }
     52 
     53 }   // namespace chromeos
     54