| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 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/sync/notifier/chrome_system_resources.h" |
| 6 |
| 7 #include <cstdlib> |
| 8 #include <string> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/string_util.h" |
| 13 #include "base/task.h" |
| 14 #include "chrome/browser/sync/notifier/invalidation_util.h" |
| 15 |
| 16 namespace sync_notifier { |
| 17 |
| 18 ChromeSystemResources::ChromeSystemResources() |
| 19 : scheduler_active_(false) {} |
| 20 |
| 21 ChromeSystemResources::~ChromeSystemResources() { |
| 22 DCHECK(!scheduler_active_); |
| 23 } |
| 24 |
| 25 invalidation::Time ChromeSystemResources::current_time() { |
| 26 return base::Time::Now(); |
| 27 } |
| 28 |
| 29 void ChromeSystemResources::StartScheduler() { |
| 30 DCHECK(!scheduler_active_); |
| 31 scheduler_active_ = true; |
| 32 } |
| 33 |
| 34 void ChromeSystemResources::StopScheduler() { |
| 35 DCHECK(scheduler_active_); |
| 36 scheduler_active_ = false; |
| 37 } |
| 38 |
| 39 void ChromeSystemResources::ScheduleWithDelay( |
| 40 invalidation::TimeDelta delay, |
| 41 invalidation::Closure* task) { |
| 42 if (!scheduler_active_) { |
| 43 delete task; |
| 44 return; |
| 45 } |
| 46 DCHECK(invalidation::IsCallbackRepeatable(task)); |
| 47 MessageLoop::current()->PostDelayedTask( |
| 48 FROM_HERE, |
| 49 NewRunnableFunction(&RunAndDeleteClosure, task), |
| 50 delay.InMillisecondsRoundedUp()); |
| 51 } |
| 52 |
| 53 void ChromeSystemResources::ScheduleImmediately( |
| 54 invalidation::Closure* task) { |
| 55 if (!scheduler_active_) { |
| 56 delete task; |
| 57 return; |
| 58 } |
| 59 DCHECK(invalidation::IsCallbackRepeatable(task)); |
| 60 MessageLoop::current()->PostTask( |
| 61 FROM_HERE, NewRunnableFunction(&RunAndDeleteClosure, task)); |
| 62 } |
| 63 |
| 64 void ChromeSystemResources::Log( |
| 65 LogLevel level, const char* file, int line, |
| 66 const char* format, ...) { |
| 67 va_list ap; |
| 68 va_start(ap, format); |
| 69 std::string result; |
| 70 StringAppendV(&result, format, ap); |
| 71 logging::LogMessage(file, line).stream() << result; |
| 72 va_end(ap); |
| 73 } |
| 74 |
| 75 } // namespace sync_notifier |
| OLD | NEW |