Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: runtime/embedders/android/sample.h

Issue 11823034: Backport some work from sample to embedder: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef EMBEDDERS_ANDROID_SAMPLE_H_
6 #define EMBEDDERS_ANDROID_SAMPLE_H_
7
8 #include "embedders/android/context.h"
9 #include "embedders/android/resource.h"
10
11 class Sample {
12 public:
13 Sample(android_app* application, const char* path)
14 : resource_(application, path),
15 buffer_(NULL),
16 length_(0) {
17 }
18
19 ~Sample() {
20 Unload();
21 }
22
23 const char* path() {
24 return resource_.path();
25 }
26
27 int32_t Load() {
28 int32_t rtn = -1;
29 if (resource_.Open() == 0) {
30 buffer_ = new uint8_t[length_ = resource_.length()];
31 rtn = resource_.Read(buffer_, length_);
32 resource_.Close();
33 }
34 return rtn;
35 }
36
37 void Unload() {
38 if (buffer_ != NULL) {
39 delete[] buffer_;
40 buffer_ = NULL;
41 }
42 length_ = 0;
43 }
44
45 private:
46 friend class SoundService;
47 Resource resource_;
48 uint8_t* buffer_;
49 off_t length_;
50 };
51
52 #endif // EMBEDDERS_ANDROID_SAMPLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698