Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/callback_old.h" | 10 #include "base/callback_old.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "chrome/browser/chromeos/login/ownership_service.h" | 14 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 // A helper that does ownership checking on the file thread and reports back the | 18 // A helper that does ownership checking on the file thread and reports back the |
| 19 // result on whatever thread the call was made on. The pattern is to construct | 19 // result on whatever thread the call was made on. The pattern is to construct |
| 20 // a checker, passing in the callback. Once the check is done, the callback will | 20 // a checker, passing in the callback. Once the check is done, the callback will |
| 21 // be invoked with the result. In order to cancel the callback, just destroy the | 21 // be invoked with the result. In order to cancel the callback, just destroy the |
| 22 // checker object. | 22 // checker object. |
| 23 class OwnershipStatusChecker { | 23 class OwnershipStatusChecker { |
| 24 public: | 24 public: |
| 25 // Callback function type. The status code is guaranteed to be different from | 25 // Callback function type. The status code is guaranteed to be different from |
| 26 // OWNERSHIP_UNKNOWN. | 26 // OWNERSHIP_UNKNOWN. The bool parameter is true when the current logged in |
|
Mattias Nissler (ping if slow)
2011/08/31 15:08:33
s/when/if/
pastarmovj
2011/08/31 15:26:36
Done.
| |
| 27 typedef Callback1<OwnershipService::Status>::Type Callback; | 27 // user is the owner. |
| 28 typedef Callback2<OwnershipService::Status, bool>::Type Callback; | |
| 28 | 29 |
| 29 explicit OwnershipStatusChecker(Callback* callback); | 30 explicit OwnershipStatusChecker(Callback* callback); |
| 30 ~OwnershipStatusChecker(); | 31 ~OwnershipStatusChecker(); |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 // The refcounted core that handles the thread switching. | 34 // The refcounted core that handles the thread switching. |
| 34 class Core : public base::RefCountedThreadSafe<Core> { | 35 class Core : public base::RefCountedThreadSafe<Core> { |
| 35 public: | 36 public: |
| 36 explicit Core(Callback* callback); | 37 explicit Core(Callback* callback); |
| 37 ~Core(); | 38 ~Core(); |
| 38 | 39 |
| 39 // Starts the check. | 40 // Starts the check. |
| 40 void Check(); | 41 void Check(); |
| 41 | 42 |
| 42 // Cancels the outstanding callback (if applicable). | 43 // Cancels the outstanding callback (if applicable). |
| 43 void Cancel(); | 44 void Cancel(); |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 void CheckOnFileThread(); | 47 void CheckOnFileThread(); |
| 47 void ReportResult(OwnershipService::Status status); | 48 void ReportResult(OwnershipService::Status status, |
| 49 bool current_user_is_owner); | |
| 48 | 50 |
| 49 scoped_ptr<Callback> callback_; | 51 scoped_ptr<Callback> callback_; |
| 50 scoped_refptr<base::MessageLoopProxy> origin_loop_; | 52 scoped_refptr<base::MessageLoopProxy> origin_loop_; |
| 51 | 53 |
| 52 DISALLOW_COPY_AND_ASSIGN(Core); | 54 DISALLOW_COPY_AND_ASSIGN(Core); |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 scoped_refptr<Core> core_; | 57 scoped_refptr<Core> core_; |
| 56 | 58 |
| 57 DISALLOW_COPY_AND_ASSIGN(OwnershipStatusChecker); | 59 DISALLOW_COPY_AND_ASSIGN(OwnershipStatusChecker); |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 } // namespace chromeos | 62 } // namespace chromeos |
| 61 | 63 |
| 62 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ | 64 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ |
| OLD | NEW |