Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / identity / identity_mint_queue.h
blobe2a0b010f2442912dbaf7629d50e6403c8a31de2
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string>
13 #include "chrome/browser/extensions/api/identity/extension_token_key.h"
15 namespace extensions {
17 // getAuthToken requests are serialized to avoid excessive traffic to
18 // GAIA and to consolidate UI pop-ups. IdentityMintRequestQueue
19 // maitains a set of queues, one for each RequestKey.
21 // The queue calls StartMintToken on each Request when it reaches the
22 // head of the line.
24 // The queue does not own Requests. Request pointers must be valid
25 // until they are removed from the queue with RequestComplete or
26 // RequestCancel.
27 class IdentityMintRequestQueue {
28 public:
29 enum MintType {
30 MINT_TYPE_NONINTERACTIVE,
31 MINT_TYPE_INTERACTIVE
34 IdentityMintRequestQueue();
35 virtual ~IdentityMintRequestQueue();
37 class Request {
38 public:
39 virtual ~Request() {}
40 virtual void StartMintToken(IdentityMintRequestQueue::MintType type) = 0;
43 // Adds a request to the queue specified by the token key.
44 void RequestStart(IdentityMintRequestQueue::MintType type,
45 const ExtensionTokenKey& key,
46 IdentityMintRequestQueue::Request* request);
47 // Removes a request from the queue specified by the token key.
48 void RequestComplete(IdentityMintRequestQueue::MintType type,
49 const ExtensionTokenKey& key,
50 IdentityMintRequestQueue::Request* request);
51 // Cancels a request. OK to call if |request| is not queued.
52 // Does *not* start a new request, even if the canceled request is at
53 // the head of the queue.
54 void RequestCancel(const ExtensionTokenKey& key,
55 IdentityMintRequestQueue::Request* request);
56 bool empty(IdentityMintRequestQueue::MintType type,
57 const ExtensionTokenKey& key);
59 private:
60 typedef std::list<IdentityMintRequestQueue::Request*> RequestQueue;
61 typedef std::map<const ExtensionTokenKey, RequestQueue> RequestQueueMap;
63 RequestQueueMap& GetRequestQueueMap(IdentityMintRequestQueue::MintType type);
64 void RunRequest(IdentityMintRequestQueue::MintType type,
65 RequestQueue& request_queue);
67 RequestQueueMap interactive_request_queue_map_;
68 RequestQueueMap noninteractive_request_queue_map_;
71 } // namespace extensions
73 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_