| OLD | NEW |
| (Empty) |
| 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/library_loader.h" | |
| 6 | |
| 7 #include <dlfcn.h> | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/metrics/histogram.h" | |
| 13 #include "base/path_service.h" | |
| 14 #include "chrome/common/chrome_paths.h" | |
| 15 #include "third_party/cros/chromeos_cros_api.h" | |
| 16 | |
| 17 namespace chromeos { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 void AddLibcrosTimeHistogram(const char* name, const base::TimeDelta& delta) { | |
| 22 static const base::TimeDelta min_time = base::TimeDelta::FromMilliseconds(1); | |
| 23 static const base::TimeDelta max_time = base::TimeDelta::FromSeconds(1); | |
| 24 const size_t bucket_count(10); | |
| 25 DCHECK(name); | |
| 26 base::Histogram* counter = base::Histogram::FactoryTimeGet( | |
| 27 std::string(name), | |
| 28 min_time, | |
| 29 max_time, | |
| 30 bucket_count, | |
| 31 base::Histogram::kNoFlags); | |
| 32 counter->AddTime(delta); | |
| 33 VLOG(1) << "Cros Time: " << name << ": " << delta.InMilliseconds() << "ms."; | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 class LibraryLoaderImpl : public LibraryLoader { | |
| 39 public: | |
| 40 LibraryLoaderImpl(); | |
| 41 | |
| 42 // LibraryLoader: | |
| 43 virtual bool Load(std::string* load_error_string) OVERRIDE; | |
| 44 }; | |
| 45 | |
| 46 LibraryLoaderImpl::LibraryLoaderImpl() {} | |
| 47 | |
| 48 bool LibraryLoaderImpl::Load(std::string* load_error_string) { | |
| 49 bool loaded = false; | |
| 50 FilePath path; | |
| 51 if (PathService::Get(chrome::FILE_CHROMEOS_API, &path)) { | |
| 52 loaded = LoadLibcros(path.value().c_str(), *load_error_string); | |
| 53 if (loaded) | |
| 54 SetLibcrosTimeHistogramFunction(AddLibcrosTimeHistogram); | |
| 55 } | |
| 56 | |
| 57 if (!loaded) { | |
| 58 LOG(ERROR) << "Problem loading chromeos shared object: " | |
| 59 << *load_error_string; | |
| 60 } | |
| 61 return loaded; | |
| 62 } | |
| 63 | |
| 64 // static | |
| 65 LibraryLoader* LibraryLoader::GetImpl() { | |
| 66 return new LibraryLoaderImpl(); | |
| 67 } | |
| 68 | |
| 69 } // namespace chromeos | |
| OLD | NEW |