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_
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
24 // The queue does not own Requests. Request pointers must be valid
25 // until they are removed from the queue with RequestComplete or
27 class IdentityMintRequestQueue
{
30 MINT_TYPE_NONINTERACTIVE
,
34 IdentityMintRequestQueue();
35 virtual ~IdentityMintRequestQueue();
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
);
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_