• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop_proxy.h"
14 #include "chrome/browser/chromeos/login/ownership_service.h"
15 
16 namespace chromeos {
17 
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
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
22 // checker object.
23 class OwnershipStatusChecker {
24  public:
25   // Callback function type. The status code is guaranteed to be different from
26   // OWNERSHIP_UNKNOWN.
27   typedef Callback1<OwnershipService::Status>::Type Callback;
28 
29   explicit OwnershipStatusChecker(Callback* callback);
30   ~OwnershipStatusChecker();
31 
32  private:
33   // The refcounted core that handles the thread switching.
34   class Core : public base::RefCountedThreadSafe<Core> {
35    public:
36     explicit Core(Callback* callback);
37 
38     // Starts the check.
39     void Check();
40 
41     // Cancels the outstanding callback (if applicable).
42     void Cancel();
43 
44    private:
45     void CheckOnFileThread();
46     void ReportResult(OwnershipService::Status status);
47 
48     scoped_ptr<Callback> callback_;
49     scoped_refptr<base::MessageLoopProxy> origin_loop_;
50 
51     DISALLOW_COPY_AND_ASSIGN(Core);
52   };
53 
54   scoped_refptr<Core> core_;
55 
56   DISALLOW_COPY_AND_ASSIGN(OwnershipStatusChecker);
57 };
58 
59 }  // namespace chromeos
60 
61 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_STATUS_CHECKER_H_
62