1 // Copyright 2013 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_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_BACKEND_UTIL_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_BACKEND_UTIL_H_
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
15 #include "chrome/browser/sync_file_system/sync_status_code.h"
16 #include "google_apis/drive/drive_api_error_codes.h"
17 #include "storage/browser/blob/scoped_file.h"
19 namespace google_apis
{
24 namespace sync_file_system
{
25 namespace drive_backend
{
29 void PutVersionToDB(int64 version
, LevelDBWrapper
* db
);
31 void PutServiceMetadataToDB(const ServiceMetadata
& service_metadata
,
33 void PutFileMetadataToDB(const FileMetadata
& file
, LevelDBWrapper
* db
);
34 void PutFileTrackerToDB(const FileTracker
& tracker
, LevelDBWrapper
* db
);
36 void PutFileMetadataDeletionToDB(const std::string
& file_id
,
38 void PutFileTrackerDeletionToDB(int64 tracker_id
, LevelDBWrapper
* db
);
40 bool HasFileAsParent(const FileDetails
& details
, const std::string
& file_id
);
42 bool IsAppRoot(const FileTracker
& tracker
);
44 std::string
GetTrackerTitle(const FileTracker
& tracker
);
46 SyncStatusCode
DriveApiErrorCodeToSyncStatusCode(
47 google_apis::DriveApiErrorCode error
);
49 // Returns true if |str| starts with |prefix|, and removes |prefix| from |str|.
50 // If |out| is not NULL, the result is stored in it.
51 bool RemovePrefix(const std::string
& str
, const std::string
& prefix
,
54 scoped_ptr
<ServiceMetadata
> InitializeServiceMetadata(LevelDBWrapper
* db
);
56 template <typename Src
, typename Dest
>
57 void AppendContents(const Src
& src
, Dest
* dest
) {
58 dest
->insert(dest
->end(), src
.begin(), src
.end());
61 template <typename Container
>
62 const typename
Container::mapped_type
& LookUpMap(
63 const Container
& container
,
64 const typename
Container::key_type
& key
,
65 const typename
Container::mapped_type
& default_value
) {
66 typename
Container::const_iterator found
= container
.find(key
);
67 if (found
== container
.end())
72 template <typename R
, typename S
, typename T
>
73 R
ComposeFunction(const base::Callback
<T()>& g
,
74 const base::Callback
<R(S
)>& f
) {
75 return f
.Run(g
.Run());
78 template <typename R
, typename S
, typename T
>
79 base::Callback
<R()> CreateComposedFunction(
80 const base::Callback
<T()>& g
,
81 const base::Callback
<R(S
)>& f
) {
82 return base::Bind(&ComposeFunction
<R
, S
, T
>, g
, f
);
85 } // namespace drive_backend
86 } // namespace sync_file_system
88 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_BACKEND_UTIL_H_