| 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. The bool parameter is true iff the current logged in | 26 // OWNERSHIP_UNKNOWN. |
| 27 // user is the owner. | 27 typedef Callback1<OwnershipService::Status>::Type Callback; |
| 28 typedef Callback2<OwnershipService::Status, bool>::Type Callback; | |
| 29 | 28 |
| 30 explicit OwnershipStatusChecker(Callback* callback); | 29 explicit OwnershipStatusChecker(Callback* callback); |
| 31 ~OwnershipStatusChecker(); | 30 ~OwnershipStatusChecker(); |
| 32 | 31 |
| 33 private: | 32 private: |
| 34 // The refcounted core that handles the thread switching. | 33 // The refcounted core that handles the thread switching. |
| 35 class Core : public base::RefCountedThreadSafe<Core> { | 34 class Core : public base::RefCountedThreadSafe<Core> { |
| 36 public: | 35 public: |
| 37 explicit Core(Callback* callback); | 36 explicit Core(Callback* callback); |
| 38 ~Core(); | 37 ~Core(); |
| 39 | 38 |
| 40 // Starts the check. | 39 // Starts the check. |
| 41 void Check(); | 40 void Check(); |
| 42 | 41 |
| 43 // Cancels the outstanding callback (if applicable). | 42 // Cancels the outstanding callback (if applicable). |
| 44 void Cancel(); | 43 void Cancel(); |
| 45 | 44 |
| 46 private: | 45 private: |
| 47 void CheckOnFileThread(); | 46 void CheckOnFileThread(); |
| 48 void ReportResult(OwnershipService::Status status, | 47 void ReportResult(OwnershipService::Status status); |
| 49 bool current_user_is_owner); | |
| 50 | 48 |
| 51 scoped_ptr<Callback> callback_; | 49 scoped_ptr<Callback> callback_; |
| 52 scoped_refptr<base::MessageLoopProxy> origin_loop_; | 50 scoped_refptr<base::MessageLoopProxy> origin_loop_; |
| 53 | 51 |
| 54 DISALLOW_COPY_AND_ASSIGN(Core); | 52 DISALLOW_COPY_AND_ASSIGN(Core); |
| 55 }; | 53 }; |
| 56 | 54 |
| 57 scoped_refptr<Core> core_; | 55 scoped_refptr<Core> core_; |
| 58 | 56 |
| 59 DISALLOW_COPY_AND_ASSIGN(OwnershipStatusChecker); | 57 DISALLOW_COPY_AND_ASSIGN(OwnershipStatusChecker); |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 } // namespace chromeos | 60 } // namespace chromeos |
| 63 | 61 |
| 64 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ | 62 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_ |
| OLD | NEW |